Programming Field

Exit - DOS/Command Prompt Reference

Exits the current command interpreter (, cmd.exe).


exit [/B] [<exit-code>]
/B [Windows NT series] When using /B in the batch program, only the batch program will exits. If ‘exit /B’ is used in the label (subroutine) called by Call command, ‘exit /B’ sets the next execution line to the next line of the caller (exiting subroutine).
<exit-code> [Windows NT series] When using /B, specifies the exit code of the batch program or the subroutine. Otherwise, specifies cmd.exe's exit code. For both cases, the caller batch program can check the exit code by using If Errorlevel.


The Exit command will exit the current running or cmd.exe. Note that without specifying /B, Exit command will exit not only the caller batch program but also the running command interpreter (

[MS-DOS/Windows 95/98/Me] When executing a batch file with ‘command /K’, Exit command used by its batch file will terminate the process, causing not prompting commands which is the behavior of /K. In this case the exit code of will be 0.

[Windows NT series] When executing a batch file with ‘cmd /K’, Exit command without /B used by its batch file will not terminate the cmd.exe process; the prompting will be performed.

[Windows NT series] The exit code will be as followings:

  • Without /B: the value of <exit-code>, or the current errorlevel value when not specifying exit code will be the exit code of cmd.exe.
  • With /B: the value of <exit-code> will be treated as the errorlevel value, and when omitting exit code the errorlevel value will not be changed. If a batch file is executed by ‘cmd /C’ and the batch file executes ‘exit /B’ (without exit code), the current errorlevel value (exit code) will be the exit code of cmd.exe. (When executed by ‘cmd /K’, the errorlevel will be inherited to the prompt, and when executing ‘exit’ or ‘exit /B’, the exit code of cmd.exe will be its errorlevel.)

For the sample of ‘exit /B’, please see Call.