How can dos batch subscripts change a var initially defined in a calling script? For example, this script is failing to increment the VAR variable, as expected. This is something like a 'global variable' that I am trying to use.
one.bat
@echo off
ENDLOCAL
SET /A GLOBALVAR=0
cmd.exe /C two.bat
ECHO ERRORLEVEL after cmd.exe : %ERRORLEVEL%
CALL two.bat
ECHO ERRORLEVEL after CALL : %ERRORLEVEL%
ECHO GLOBALVAR=%GLOBALVAR%
pause
two.bat
@ECHO off
:: error if GLOBALVAR variable not detected
IF NOT DEFINED GLOBALVAR EXIT /B 9
SET /A GLOBALVAR=%GLOBALVAR%+1
EXIT /B 0
And the output:
ERRORLEVEL after cmd.exe : 0
ERRORLEVEL after CALL : 0
GLOBALVAR=1
Press any key to continue . . .