1

重複の可能性:
Windows コマンド ラインからアプリケーションの終了コードを取得するにはどうすればよいですか?

1バッチ内で呼び出している Perl スクリプトは、、、2またはを返します3。引数 829 を指定してこの perl スクリプトを呼び出し、スクリプトの終了コードを取得するための構文は何ですか?

 Perl.exe listMembership.pl 829 in cmd.exe

 @echo off
 set retVal=Perl.exe listMembership.pl 829
 echo %retVal%
4

1 に答える 1

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 数値 最後のプログラムが実行された場合に真の条件を指定します
                数値以上の終了コードを返しました
                指定。
于 2012-07-03T21:57:00.463 に答える