私が取り組んでいるバッチ スクリプトでは、バッチ スクリプトの FOR ループから 2 つのサブルーチンを呼び出した後、変数値が保持されません。シナリオをデモするコード スニペットを次に示します。
set ERRORCODE=0
FOR ... do (
call :myRoutine
@ECHO %ERRORCODE% // Here I am expecting the ERRORCODE to be a 1 (non-zero), but I am seeing that it is getting reset to 0
)
myRoutine:
call :another
IF %ERRORCODE% NEQ 0 GOTO :EOF // Here I am getting the ERRORCODE as 1 as expected
...
GOTO :EOF
another:
something went wrong here..
IF %ERRORLEVEL% NEQ 0 (
set ERRORCODE=1
GOTO :EOF
)