KBEC-00066 - Propagating errors in Windows commands to an ElectricCommander job step outcome

Article ID:360033194671
1 minute readKnowledge base

Description

Steps using Windows CMD commands can return a successful exit code (0) even if individual commands within the step fail. Reason: the last command in the step determines the exit code.

Solution

Save the ERRORLEVEL of the command, perform the other operations, and then return the desired error level on exit:

ectool badcommand
set SAVED_ERRORLEVEL=%ERRORLEVEL%
echo Saved errorlevel is %SAVED_ERRORLEVEL%
rem Show that the errorlevel has been reset to 0
echo Current errorlevel is %ERRORLEVEL%
exit %SAVED_ERRORLEVEL%