我正在运行一个程序,想查看它的返回代码是什么(因为它会根据不同的错误返回不同的代码)。
我知道在Bash中,我可以通过运行
回声$?
在Windows上使用cmd.exe怎么办?
名为的伪环境变量errorlevel
存储退出代码:
echo Exit Code is %errorlevel%
另外,该if
命令具有特殊的语法:
if errorlevel
有关if /?
详细信息,请参见。
@echo off
my_nify_exe.exe
if errorlevel 1 (
echo Failure Reason Given is %errorlevel%
exit /b %errorlevel%
)
警告:如果设置了环境变量名称errorlevel
,%errorlevel%
将返回该值,而不是退出代码。使用(set errorlevel=
)清除环境变量,从而允许errorlevel
通过%errorlevel%
环境变量访问的真实值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句