How to return an error code without closing the Command Prompt window?
You can use the pause
command before calling exit.
If you don't like the message:
pause > nul
If you don't want to close the window, but just go back to the command prompt, you should use
EXIT /B
To get help for command prompt commands use their /? option. Exit /?
shows:
Quits the CMD.EXE program (command interpreter) or the current batch script.
EXIT [/B] [exitCode]
/B specifies to exit the current batch script instead of CMD.EXE. If executed from outside a batch script, it will quit CMD.EXE
exitCode specifies a numeric number. if /B is specified, sets ERRORLEVEL that number. If quitting CMD.EXE, sets the process exit code with that number.
So you want
IF %ERRORLEVEL% GEQ 1 EXIT /B 2