在运行它之前,我无法可靠地保证二进制文件存在
你可以使用 which.cmd
查看二进制文件是否存在,并返回一个合适的 ERRORLEVEL
。
您的问题的解决方法(禁用“Windows无法找到'[foo] .exe'”弹出窗口)
- 跑
which program
- 检查
ERRORLEVEL
- 跑
start
除非 program
找到了。
:: WHICH.CMD CommandName [ReturnVar]
::
:: Determines the full path of the file that would execute if
:: CommandName were executed.
::
:: The result is stored in variable ReturnVar, or else it is
:: echoed to stdout if ReturnVar is not specified.
::
:: If no file is found, then an error message is echoed to stderr.
::
:: The ERRORLEVEL is set to one of the following values
:: 0 - Success: A matching file was found
:: 1 - No file was found and CommandName is an internal command
:: 2 - No file was found and CommandName is not an internal command
:: 3 - Improper syntax - no CommandName specified
以下链接包含完整的源代码 which.cmd
(由...撰写) 超级用户 用户 德贝纳姆 )。
资源 which.cmd - 显示可执行文件的完整路径。
START
另一个bat脚本本身启动可执行文件而没有START
因为在这种情况下,第二个shell应该只是打印错误。