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,418 other followers

How do I get the application exit code from a Windows command line? – Stack Overflow

Posted by jpluimers on 2021/07/15

[WayBack] How do I get the application exit code from a Windows command line? – Stack Overflow solutions below.

Note they ONLY work when nobody sets the ERRORLEVEL environment variable.

  • You can quickly see what app returns: app.exe & echo %errorlevel% – [WayBack] marbel82
  • something.exe
    echo Exit Code is %errorlevel%

    – [WayBack] Samuel Renkert

  • start /wait something.exe
    echo %errorlevel%

    – [WayBack] Gary

  • @echo off
    my_nify_exe.exe
    if %ERRORLEVEL% EQU 0 (
       echo Success
    ) else (
       echo Failure Reason Given is %errorlevel%
       exit /b %errorlevel%
    )

    – [WayBack] Curtis Yallop

  • It’s worth noting that .BAT and .CMD files operate differently.Reading https://ss64.com/nt/errorlevel.html it notes the following:

    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 .

    This was causing me no end of grief as I was executing successive commands, but the ERRORLEVEL would remain unchanged even in the event of a failure. – [WayBackRockDoctor

–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: