Search notes:

cmd.exe - exit

exit quits the cmd.exe command interpreter or terminates a batch file.

Leaving a batch file

In order to exit a batch file, exit /b should be used (because exit within a batch file quits cmd.exe).

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.
The returned value is kept in the %errorlevel% variable.
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%

See also

cmd.exe: Built-in commands

Index