可能重复:
How do I get the application exit code from a Windows command line?
我在批处理中调用的Perl脚本返回1
,2
或3
。使用参数829调用此perl sript并捕获脚本的退出代码的语法是什么?
Perl.exe listMembership.pl 829 in cmd.exe
@echo off
set retVal=Perl.exe listMembership.pl 829
echo %retVal%
答案 0 :(得分:2)
在命令行上查看if /?
的输出。如果没有cmd
扩展名,最小公分母批处理脚本将是:
@echo off
Perl.exe listMembership.pl 829
if errorlevel 4 goto error
if errorlevel 3 goto exit3
if errorlevel 2 goto exit2
if errorlevel 1 goto exit1
if errorlevel 0 goto exit0
:error
echo:Unexpected exit code %ERRORLEVEL%
goto end
:exit3
echo:Forbnicate
goto end
:exit2
echo:Colormaticate
goto end
:exit1
echo:Motorcade
goto end
:exit0
echo:Is this really success?
goto end
:end
echo:Done
请注意,errorlevel
检查必须按降序排列,因为:
ERRORLEVEL number Specifies a true condition if the last program run returned an exit code equal to or greater than the number specified.