在我正在处理的批处理脚本中,在调用 2 个子例程后没有保留变量值,其中一个来自批处理脚本的 FOR 循环。这是一个演示场景的代码片段:
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
)