我有一个 Windows 7 x64 系统,我想让一个批处理文件执行一个程序,然后测试进程的退出代码并根据该退出代码执行一些操作。例如:
@rem sets the process exit code to 1. should print "success!" actually prints nothing
cmd /c exit 1
if NOT ERRORLEVEL 0 echo success!
@rem prints "success!" as expected
cmd /c exit 1
if errorlevel 1 echo success!
@rem prints "failure!" even though the exit code is 0
cmd /c exit 0
if errorlevel 1 echo failure!
@rem prints "ERRORLEVEL=1" as expected
cmd /c exit 1
echo ERRORLEVEL=%ERRORLEVEL%
我需要做什么才能从批处理文件中获得预期的行为?