[英]How to exit 'git-cmd.exe' after running a command via it in a batch file?
I'm writing a batch file that runs a command via git-cmd.exe
but it doesn't run the command(s) after it. 我正在编写一个通过git-cmd.exe
运行命令的批处理文件,但此命令之后不运行该命令。
I've tried to use CALL
, START /WAIT
, and START /B /WAIT
. 我尝试使用CALL
, START /WAIT
和START /B /WAIT
。 All have the same behavior. 全部具有相同的行为。 Maybe there is a parameter should be sent to git-cmd.exe
to execute the command and exit but I didn't find any guide explaining how to use git-cmd.exe
. 也许应该向git-cmd.exe
发送一个参数以执行命令并退出,但是我没有找到任何指南来解释如何使用git-cmd.exe
。
This is a sample batch file: 这是一个示例批处理文件:
@ECHO OFF
SET "PATH=C:\Ruby26-x64\bin;C:\Program Files\nodejs;%PATH%"
SET "CurrentDirectory=%CD%"
CD /D "%UserProfile%\AppData\Local\GitHub\PortableGit_*\"
SET "GitDirectory=%CD%"
CD /D "%CurrentDirectory%"
"%GitDirectory%/git-cmd.exe" CALL rake build
PAUSE
The command passed to git-cmd.exe
is executed but the PAUSE
command doesn't execute until I type EXIT
command manually in the 'Command Prompt' window. 传递到git-cmd.exe
的命令已执行,但直到我在“命令提示符”窗口中手动键入EXIT
命令, PAUSE
命令才执行。
I've also tried a simple DIR
command instead of rake build
but the same issue still occurs: 我还尝试了一个简单的DIR
命令而不是rake build
但是仍然出现相同的问题:
"%GitDirectory%/git-cmd.exe" DIR
PAUSE
Thanks to the suggestions, the issue was resolved by passing EXIT
command to git-cmd.exe
as follows: 多亏了这些建议,通过将EXIT
命令传递给git-cmd.exe
可以解决此问题,如下所示:
@ECHO OFF
SET "PATH=C:\Ruby26-x64\bin;C:\Program Files\nodejs;%PATH%"
SET "CurrentDirectory=%CD%"
CD /D "%UserProfile%\AppData\Local\GitHub\PortableGit_*\"
SET "GitDirectory=%CD%"
CD /D "%CurrentDirectory%"
"%GitDirectory%/git-cmd.exe" "CALL rake build & EXIT"
PAUSE
There was a useful conversation between me and someone else (I think his name was mony) but it was deleted, don't know why?! 我和其他人(我想他的名字叫mony)之间进行了有益的交谈,但被删除了,不知道为什么?! He sent me this link with the difference between &
and &&
between commands: https://stackoverflow.com/a/25344009/9586127 他向我发送了此链接,其中包含&
和&&
之间的命令区别: https : //stackoverflow.com/a/25344009/9586127
The &
before the EXIT
command in order to execute both commands independent on result of the first one. EXIT
命令前的&
,以便独立于第一个命令的结果执行两个命令。 If &&
is used, the EXIT
command will be executed only if the first command succeeded (exit code 0). 如果使用&&
,则仅在第一个命令成功(退出代码0)时才执行EXIT
命令。
In addition, he told me a way to replace the lines 3:6 by one line to be: 此外,他还告诉我一种将3:6行替换为以下一行的方法:
FOR /D %%I IN ("%LocalAppData%\GitHub\PortableGit_*") DO SET "GitDirectory=%%I"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.