We have some error handling setup in our scripts as shown:
set ret = %ERRORLEVEL%
if %ERRORLEVEL% == 0 GOTO PPCOK
if not %ret% == 0 GOTO ERROR1
Someone else wrote the above, I however have a few concerns about it actually working properly.
I have read that if you do a check for ERRORLEVEL = 0 it actually is checking if the errorlevel is 0 or higher. My assumption is that it would always go to the PPCOK label?
Also, most examples on the web use "IF ERRORLEVEL 1" or some show "IF %ERRORLEVEL% EQU 1" and above uses "IF %ERRORLEVEL% == 0" I am wondering if there is a valid case for choosing which of these three methods should be used?
On a side note I am not sure why they stored the errorlevel in another variable and used it on the second if statement rather than just doing another IF NOT %ERRORLEVEL% ...
if %ERRORLEVEL% == 0will only be true if the error level is actually zero. This method is usually preferable in my opinion, although it will fail in the pathological case where someone has created an environment variable namedERRORLEVEL. You are right in thinking that there is no need for theretvariable, in fact the secondifstatement is entirely redundant, you could just sayGOTO ERROR1.