Can a batch file capture the exit codes of the commands it is invoking?

Matt picture Matt · Sep 10, 2010 · Viewed 45.2k times · Source

Basically, let's say that I have a batch file that calls myapp1.exe and myapp1.exe exits with Exit Code 1. Can the batch file capture this information and either force the batch file to exit with that same exit code or perform some other logic?

Answer

Joey picture Joey · Sep 10, 2010
@echo off
rem ...
set errorlevel=
MyApp1.exe
exit /b %errorlevel%

would be the explicit variant.