exit /b in Windows batch script

You must be familiar with the exit command. If you execute this command in a DOS window, the DOS window closes and the cmd process exits. This is like closing the window by clicking the “Close” button on the title bar of the cmd window.

exit /b is often seen in a Windows bat file. When the script runs to the “exit /b” line,  the commands after this line are not executed and the commands after the calling of current script continue. If current script was run/called directly by the cmd process, the cmd process won’t exit. This is exactly the aim of the /b(b means batch) switch. Without the /b switch, the script exits and the cmd running the script exits too. If you run exit /b in the cmd window(not in a bat script), the cmd exits.

You can provide an exit code to the exit command, i.e., exit [/b] exitCode. If the cmd process exits(as in the case you run the exit command in the cmd window or use “exit exitCode” in a bat script), the exitcode will be set to the exit code of the cmd process. If you use exit /b exitCode in a batch file, since the cmd does not end when the script ends, there would be no exit code to set, in that case, the ERRORLEVEL environment variable of the cmd process is set to the exitCode.

 

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Leave a Reply