Passing a return value from a batch file to its caller
A batch file can pass an integer value between -2147483648 (-231) and 2147483647 (231-1) to a calling batch file or command interpreter.
This is demonstrated with the following two
batch files:
callee.bat
and
caller.bat
.
callee.bat
callee.bat
is the batch file that is supposed to be called from caller.bat
. It prints some idle text and the returns 42 to the caller.
echo This is a simple batch file
echo that uses "exit /b 42" to return a
echo a value to the caller
exit /b 42
caller.bat
caller.bat
uses
call
to start
callee.bat
and the prints (
echo
) the returned value:
@echo off
call callee.bat
echo(
echo callee.bat "returned" %errorlevel%