windows batch file exits when running mercurial commands
For daily backup of my mercurial repositories on Windows XP I used a simple batch file hg_backup.bat
which just did some directory changes and mercurial calls with a pause
command in the end like this:
@Z:
@cd \hg_backup\drawings
hg pull -v
@cd \hg_backup\src\scripts
hg pull -v
@cd \hg_backup\eagle4\lbr
hg pull -v
@pause
This worked 开发者_StackOverflow社区fine with mercurial up to 1.7 (installed with TortoiseHg). However since mercurial 1.8 it starts the very first mercurial command and then exits abruptly without reaching the following commands or even the end of the script. The command window just disappears.
I had the same problem some time before, when I tried the same thing with git, but didn't investigate further, because I use git for one repository only. It seems to me, there's some return code of the hg command line call involved which causes the script to end instead of executing the other command but I couldn't verify this yet.
Has anyone an idea why this happens or maybe even how to fix it?
If your hg
is a hg.bat
or hg.cmd
, use call hg
and see if it starts working.
The command.com
shell executes batch files replacing the old script (to save memory), and requires using call
to start a batch script and continue execution later. This behavior remains in Windows cmd.exe
for compatibility.
I had the exact same problem, but the solution provided by @grawity didn't work for me (and I have no idea why).
The solution in my case was to replace call
with cmd /C
, like so:
cmd /C hg sum
cmd /C hg stat
精彩评论