.bat文件开启常用软件:start顺序很关键

使用脚本一键开启印象笔记,VSCode和Chrome时遇到的坑…


@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也会同时关闭。这很有趣。

趁你还年轻 wechat
欢迎扫码关注我的微信公众号!