@echo off
echo Starting evernote...
start "" "C:\Program Files (x86)\Evernote\Evernote\Evernote.exe
echo Starting vscode...
start "" "C:\Program Files (x86)\Microsoft VS Code\Code.exe"
echo Starting Chrome...
start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
另一种写法是(这种不推荐,可以用来理解):
@echo off
echo Starting evernote...
cd C:\Program Files (x86)\Evernote\Evernote
strat Evernote.exe
cd C:\Program Files (x86)\Microsoft VS Code
strat Code.exe
echo Starting Chrome...
cd C:\Program Files (x86)\Google\Chrome\Application
start chrome.exe
存在的问题是,不能自动退出...
方案1:删繁就简 自动退出失败
start "" "C:\Program Files (x86)\Evernote\Evernote\Evernote.exe"
start "" "C:\Program Files (x86)\Microsoft VS Code\Code.exe"
start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
方案2:taskkill杀死进程 自动退出失败 打不开vscode
start "" "C:\Program Files (x86)\Evernote\Evernote\Evernote.exe"
start "" "C:\Program Files (x86)\Microsoft VS Code\Code.exe"
start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
taskkill /im cmd.exe
方案3:到segmentfault提问...
方案4:调整了下开启顺序 自动退出成功
start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
start " " "C:\Program Files (x86)\Evernote\Evernote\Evernote.exe"
start " " "C:\Program Files (x86)\Microsoft VS Code\Code.exe"
方案5:继续试验 自动退出成功
@echo off
echo Starting evernote...
start "" "C:\Program Files (x86)\Evernote\Evernote\Evernote.exe"
echo Starting Chrome...
start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
echo Starting vscode...
start "" "C:\Program Files (x86)\Microsoft VS Code\Code.exe"
由此可见,bat文件中应用程序的开启顺序可能也会导致exit命令的失效。
PS:
添加了pause命令后,会出现“按任意键以继续...”,但是会按任意键继续失败,更为严重的是,关闭cmd窗口后vscode也会同时关闭。这很有趣。
期待和大家交流,共同进步,欢迎大家加入我创建的与前端开发密切相关的技术讨论小组:
- SegmentFault技术圈:ES新规范语法糖
- SegmentFault专栏:趁你还年轻,做个优秀的前端工程师
- 知乎专栏:趁你还年轻,做个优秀的前端工程师
- Github博客: 趁你还年轻233的个人博客
- 前端开发QQ群:660634678
微信公众号: 人兽鬼 / excellent_developers
努力成为优秀前端工程师!