Batch File Return Codes with executables

1.2k Views Asked by At

Possibly a really dumb question:

If a batch file runs an executable and the executable fails, does the batch file return the error code of the executable or does it return 0 for finishing its code? (or some other return code?)

Relevance: I'm created tasks for a task scheduler to run batch files that run executables, and for some of them I am writing error checking ones to send me an email if the executables fail

1

There are 1 best solutions below

0
On BEST ANSWER

most executables (not all) do return a returncode. In batch, use %errorlevel% to reference it. (do it quite after the command, because other commands may overwrite it) Usually 0 means "Success/Errorfree". Non-zero values usually mean "Error/Failed" (there are no "standards", every executable may use it's own values for different errors, e.g. 0=command successful, 1=command failed, 2= wrong parameter, 3=ReadError, ...)

dir NonExistingFile.ext
echo %errorlevel%