EXIT – Windows CMD Command


Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Quit the current batch script, quit the current subroutine or quit the command processor (CMD.EXE) optionally setting an errorlevel code.

To close an interactive command prompt, the keyboard shortcut ALT + F4 is an alternative to typing EXIT.

Errorlevel

EXIT /b has the option to set a specific errorlevel, EXIT /b 0 for sucess, EXIT /b 1 (or greater) for an error.
The exit code can be an integer of up to 10 digits in length (positive or negative).

EXIT without an ExitCode acts the same as goto:eof and will not alter the ERRORLEVEL

n.b. You should never attempt to directly write to the %ERRORLEVEL% variable, (SET ERRORLEVEL n ) instead use EXIT /b n as a safe way to set the internal ERRORLEVEL pseudo-variable to n.

When EXIT /b used with FOR /L, the execution of the commands in the loop is stopped, but the loop itself continues until the end count is reached. This will cause slow performance if the loop is (pointlessly) counting up to a large number.
In the case of an infinite loop, this EXIT /b behavior will cause the script to hang until manually terminated with Ctrl + C

Exiting nested FOR loops, EXIT /b can be used to exit a FOR loop that is nested within another FOR loop.
This will only work if the inner FOR loop is contained in a separate subroutine so that EXIT /b (or goto:eof) will terminate the subroutine.

EXIT is an internal command.
If Command Extensions are disabled, the EXIT command will still work but may output a spurious ‘cannot find the batch label‘ error.

You may also like...

1 Response

  1. ปั้มไลค์ says:

    Like!! Great article post.Really thank you! Really Cool.

Leave a Reply

Your email address will not be published. Required fields are marked *