Errorlevel different outcomes.
Posted: 19 Jan 2010 05:30
Hi All,
I have an issue with the errorlevel setting. Here is the example scenario.
From file a.bat
call b.bat
if %errorlevel% 1 goto subBadEnd
if %errorlevel% 0 goto subGoodEnd
REM *********************************************************
REM Fault handler
REM *********************************************************
: subBADEND
echo %date% %time%: *******************************
echo %date% %time%: FAULT - err=%errorlevel%
echo %date% %time%: Dumping vars with 'set'
set
echo %errorlevel%
echo %date% %time%: *******************************
goto subEND
REM *********************************************************
REM Success handler
REM *********************************************************
: subGOODEND
echo %date% %time%: SUCCESS ok=%errorlevel%
echo %date% %time%: *******
goto subEND
REM *********************************************************
REM The end
REM *********************************************************
:subEND
echo error=%errorlevel%
File b.bat does some processing. it has the same errorchecking as above after various commands.
when b.bat fails with say errorcode 1 a.bat will finish with errorcode 0. i imagine this is because commands such as 'set' execute correctly and return an errorelvel of 0. is this correct?
when i ran this from another machine however, it ended with 1. the code may have differed slightly but im trying to understand the logic behind the errorlevels with relation to this program.
i'd very much appreciate your help.
Thanks,
R
I have an issue with the errorlevel setting. Here is the example scenario.
From file a.bat
call b.bat
if %errorlevel% 1 goto subBadEnd
if %errorlevel% 0 goto subGoodEnd
REM *********************************************************
REM Fault handler
REM *********************************************************
: subBADEND
echo %date% %time%: *******************************
echo %date% %time%: FAULT - err=%errorlevel%
echo %date% %time%: Dumping vars with 'set'
set
echo %errorlevel%
echo %date% %time%: *******************************
goto subEND
REM *********************************************************
REM Success handler
REM *********************************************************
: subGOODEND
echo %date% %time%: SUCCESS ok=%errorlevel%
echo %date% %time%: *******
goto subEND
REM *********************************************************
REM The end
REM *********************************************************
:subEND
echo error=%errorlevel%
File b.bat does some processing. it has the same errorchecking as above after various commands.
when b.bat fails with say errorcode 1 a.bat will finish with errorcode 0. i imagine this is because commands such as 'set' execute correctly and return an errorelvel of 0. is this correct?
when i ran this from another machine however, it ended with 1. the code may have differed slightly but im trying to understand the logic behind the errorlevels with relation to this program.
i'd very much appreciate your help.
Thanks,
R