I have written a .bat
file to first run a program, if it is correctly finished I run another program and check return value of it.
first-program.exe
Both instances of %ERRORLEVEL%
are in the same block of code and thus both get their values at the moment when the first instance is updated. Consider enabling delayed expansion of variables with enabledelayedexpansion
and replacing %ERRORLEVEL%
with !ERRORLEVEL!
to update each instance individually. For instance:
@echo off
setlocal enabledelayedexpansion
first-program.exe
IF "!ERRORLEVEL!"=="0" (
second-program.exe
IF "!ERRORLEVEL!"=="0" (
ECHO OK
) ELSE (
ECHO NOK
)
)
endlocal