Consultor Eletrônico



Kbase P23582: How to trap return exit code from an executable in batch file?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   22/02/2007
Status: Unverified

GOAL:

How to trap return exit code from an executable in batch file?

FIX:

For Windows/DOS platforms:
The exit code can be trapped in a MS-DOS batch file with the IF ERRORLEVEL n GOTO statement as follows:
myexec argv1 argv2 ...
IF NOT ERRORLEVEL 1 GOTO done:
ECHO AN error occurred with exit code 1 or higher.
:DONE
ECHO End of batch file.

For UNIX scripts:
myexec argv1 argv2 ...
ret="$?"
if [ "$ret" -eq "0" ]; then
echo "myexec ended normally"
else
echo "myexec ended abnormally"
fi