The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,433 other followers

`exit /b #`: set `errorlevel` to `#`, then exit batch file or subroutine – via: Errorlevel – Windows CMD – SS64.com

Posted by jpluimers on 2020/11/25

I seem to always forget how to set an error leve in side a batch file, but [WayBack] Errorlevel – Windows CMD – SS64.com tells how:

  • When ending a [WayBacksubroutine, you can use EXIT /b N to set a specific ERRORLEVEL N.
  • You can make a [WayBackbatch file return a non-zero exit code by using the [WayBackEXIT command.

    Exit 0
    Exit /B 5

    To force an ERRORLEVEL of 1 to be set without exiting, run a small but invalid command like [WayBack]COLOR 00 

    There is a key difference between the way .CMD and .BAT batch files set errorlevels:

    An old .BAT batch script running the ‘new’ internal commands: APPEND, ASSOC, PATH, PROMPT, FTYPE and SET will only set ERRORLEVEL if an error occurs. So if you have two commands in the batch script and the first fails, the ERRORLEVEL will remain set even after the second command succeeds.

    This can make debugging a problem BAT script more difficult, a CMD batch script is more consistent and will set ERRORLEVEL after every command that you run [[archive.is]source].

It looks like I already used a bare EXIT /B without explaining it in Source: stop/start IIS.

Further reading, including the difference between subroutines, blocks and batch files:

Finally saving Google Groups messages in the way back machine:

  1. Convert the URL
  2. Save the latter in archive.is

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: