Close cmd window after Git command in batch script

社会主义新天地 提交于 2020-01-15 09:15:12

问题


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

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.

How can I close the window? (I've seen plenty of speculative answers in other posts, I'm asking how I can really/actually close the window in this case)


回答1:


try with :

start "Window title" "C:\pathto\Git\git-cmd.exe" git bundle create X:/outpath/name.bundle --branches --tags ^&exit 

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.



来源:https://stackoverflow.com/questions/41637282/close-cmd-window-after-git-command-in-batch-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!