在批处理脚本中的Git命令后关闭cmd窗口 [英] Close cmd window after Git command in batch script
问题描述
我编写了一个简短的批处理脚本(Windows 7)来捆绑Git存储库并将副本保存在网络驱动器上:
I wrote a short batch script (Windows 7) to bundle a Git repo and save a copy on a network drive:
@ECHO OFF
cd /D E:/mypath/myrepo.git
start "Window title" "C:\pathto\Git\git-cmd.exe" git bundle create X:/outpath/name.bundle --branches --tags
这按预期工作,但是,我希望完成后关闭窗口.我尝试了exit
,但是窗口只是返回到cd
指定的目录,并保持打开状态.
This works as expected, however, I would like the window to close when complete. I tried exit
but the window just returns to the directory specified by cd
, and remains open.
如何关闭窗口? (我在其他帖子中看到了很多推测性答案,我想问的是在这种情况下如何真正/实际上关闭窗口)
推荐答案
尝试使用:
start "Window title" "C:\pathto\Git\git-cmd.exe" git bundle create X:/outpath/name.bundle --branches --tags ^&exit
要退出控制台,您当然需要exit
命令.要在一行上执行两个命令,通常使用&符.但是在这种情况下,您希望退出是START命令的一部分,但在启动后不执行,因此您逃脱 &
并插入符号.
To exit the console of course you need exit
command. To execute two commands on one line you ussally use ampersand . But in this case you want the exit as part of START command ,but not be executed after start so you escape the &
with caret.
这篇关于在批处理脚本中的Git命令后关闭cmd窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!