Symptoms

When adTempus runs a batch file that in turn calls another batch file, adTempus may report an exit code of 0 for the step even though the batch file appears to be returning a non-zero exit code.

Example

Suppose you have two batch files.

outer_batch.bat contains the following statements:

@echo off
call inner_batch.bat
echo outer ERRORLEVEL: %ERRORLEVEL%

inner_batch.bat performs various tasks and returns a nonzero exit code on failure:

@echo off
setlocal

...execute additional statements...

java runner.MainBatchRunner %3 %5 %6 %7 
if not (%ERRORLEVEL%)==() (
    set ERRLVL=%ERRORLEVEL%
)

...execute additional statements...

echo inner ERRLVL: %ERRLVL%
exit /b %ERRLVL%
endlocal

You run outer_batch.bat from adTempus and capture the console output. Reviewing the output you see that the java command failed and returned an exit code of -1. The two echo statements both show that the ERRORLEVEL value is correctly set to -1:

inner ERRLVL: -1
outer ERRORLEVEL: -1

Generally, the ERRORLEVEL value is the same as the exit code that is returned by a batch file. In this case, however, adTempus reports an exit code of 0 for outer_batch.bat.

Cause

This is an issue with Windows batch file handling. adTempus is correctly passing through the exit code of 0 that Windows is reporting when outer_batch.bat ends.

Workaround

To work around this problem, you can explicitly set the exit code when outer_batch.bat ends, by adding an exit statement to the end:

@echo off
call inner_batch.bat
echo outer ERRORLEVEL: %ERRORLEVEL%
exit %ERRORLEVEL%

 Windows will now report the exit code as -1, which will be reflected in adTempus.