After running a MS DOS command in cmd.exe i was checking the exit code using echo %ERRORLEVEL%. However I guess before running this i should clear the variable: %ERRORLEVEL%.
Am i correct? Also how to clear this variable?
Thank you.
After running a MS DOS command in cmd.exe i was checking the exit code using echo %ERRORLEVEL%. However I guess before running this i should clear the variable: %ERRORLEVEL%.
Am i correct? Also how to clear this variable?
Thank you.
As twasbrillig wrote, I think this is already answered in:
What is the easiest way to reset ERRORLEVEL to zero?
And I would mark as best the answer:
cmd /c exit /b 0
Use the verify
command. We are causing the ErrorLevel variable to be reset by just performing a command that we know will succeed. So this can be done with any command that you know will succeed. Verify is just the default from what I have seen.
verify >nul
Also, you will want to only clear the variable before calling the command that returns the exit code.
verify >nul
command that returns an exit code
echo %ErrorLevel%