start 命令与自定义启动脚本的制作
运行 shell:startup
,创建一个 bat 脚本,如 startup.bat
。
命令
- 启动程序时,设置 CPU 调度它的优先级,如影子输入法,这输入法总有概率会在第一次运行时打第一个字时卡死。
start /high shadowIME
其他优先级:
/LOW Start application in the IDLE priority class.
/NORMAL Start application in the NORMAL priority class.
/HIGH Start application in the HIGH priority class.
/REALTIME Start application in the REALTIME priority class.
/ABOVENORMAL Start application in the ABOVENORMAL priority class.
/BELOWNORMAL Start application in the BELOWNORMAL priority class.
- 后台启动,使得脚本不会等已启动的程序退出后才退出,因为有些程序在用 start 启动时会在终端有输出,导致脚本无法退出。
call "cmd /c start bash"
- 控制几个程序间的启动顺序,如延时 5秒 启动 chrome,
timeout /nobreak /t 5
# timeout 延时过短易出 bug,可以换用 ping
ping -n 5 127.0.0.1>nul
start chrome
在脚本的最后加上延时,以实现启动脚本的黑窗口不立即退出,方面排错,也可以用 pause
,不退出。
timeout /nobreak /t 30
ping -n 30 127.0.0.1>nul
- 最小/大化打开,仅部分程序有效果,但是都不会报错。
start /min notepad
/max
call "cmd /c start /min notepad"
- 注释
REM comment
REM 中文注释有时会报错
例:
启动 a,b,c, 三个程序。要求启动顺序为 a,b,c,每两个程序启动间隔为 5s, a 的优先级为高, b 的启动不影响终端的退出,c 以最小化启动,脚本在所有启动任务执行完后再延 30s 退出黑窗口。
startup.bat
start /high a
ping -n 5 127.0.0.1>nul
call "cmd /c start b"
ping -n 5 127.0.0.1>nul
start /min c
ping -n 30 127.0.0.1>nul