如何从Windows命令行获取应用程序退出代码? [英] How do I get the application exit code from a Windows command line?
问题描述
我正在运行一个程序,希望看到它的返回代码是什么(因为它返回基于不同错误的不同代码)。
我知道在Bash我可以
p>在Windows上使用cmd.exe时,该怎么办?
名为 errorlevel
存储退出代码:
echo退出代码是%errorlevel%
此外,如果
命令有特殊语法:
if errorlevel
示例
@echo off
my_nify_exe.exe
如果errorlevel 1(
echo失败原因是%errorlevel%
exit / b%errorlevel %
)
警告:如果您设置环境变量名称 errorlevel
,%errorlevel%
将返回该值,而不是退出代码。使用(设置 errorlevel =
)清除环境变量,允许通过 errorlevel
访问真实值< c $ c>%errorlevel%环境变量。
I am running a program and want to see what its return code is (since it returns different codes based on different errors).
I know in Bash I can do this by running
echo $?
What do I do when using cmd.exe on Windows?
A pseudo environment variable named errorlevel
stores the exit code:
echo Exit Code is %errorlevel%
Also, the if
command has a special syntax:
if errorlevel
See if /?
for details.
Example
@echo off
my_nify_exe.exe
if errorlevel 1 (
echo Failure Reason Given is %errorlevel%
exit /b %errorlevel%
)
Warning: If you set an environment variable name errorlevel
, %errorlevel%
will return that value and not the exit code. Use (set errorlevel=
) to clear the environment variable, allowing access to the true value of errorlevel
via the %errorlevel%
environment variable.
这篇关于如何从Windows命令行获取应用程序退出代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!