Skip to content
Fix Code Error

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

March 13, 2021 by Code Error
Posted By: Skrud

I am running a program and want to see what its return code is (since it returns different codes based on different errors).

I know in Bash I can do this by running

echo $?

What do I do when using cmd.exe on Windows?

Solution

A pseudo environment variable named errorlevel stores the exit code:

echo Exit Code is %errorlevel%

Also, the if command has a special syntax:

if errorlevel

See if /? for details.

Example

@echo off
my_nify_exe.exe
if errorlevel 1 (
   echo Failure Reason Given is %errorlevel%
   exit /b %errorlevel%
)

Warning: If you set an environment variable name errorlevel, %errorlevel% will return that value and not the exit code. Use (set errorlevel=) to clear the environment variable, allowing access to the true value of errorlevel via the %errorlevel% environment variable.

Answered By: DrFloyd5

Related Articles

  • What are the undocumented features and limitations…
  • What's the difference between eval, exec, and compile?
  • Simplest way to create Unix-like continuous pipeline…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • What is a NullReferenceException, and how do I fix it?
  • data.table vs dplyr: can one do something well the…
  • How to filter a RecyclerView with a SearchView
  • PHP parse/syntax errors; and how to solve them
  • What is your most productive shortcut with Vim?
  • Ukkonen's suffix tree algorithm in plain English
  • Removing double quotes from variables in batch file…
  • How can I find the product GUID of an installed MSI setup?
  • For-each over an array in JavaScript
  • How to paste yanked text into the Vim command line
  • What does "Fatal error: Unexpectedly found nil while…
  • How does PHP 'foreach' actually work?
  • Identifying and solving…
  • What are the new features in C++17?
  • Setting up and using Meld as your git difftool and mergetool
  • Usage of __slots__?
  • Reference - What does this regex mean?
  • Examples of GoF Design Patterns in Java's core libraries
  • AppCompat v7 r21 returning error in values.xml?
  • How can I exclude all "permission denied" messages…
  • How do I use shell variables in an awk script?
  • How to generate a random string of a fixed length in Go?
  • Difference between variable declaration syntaxes in…
  • How to run a shell script on a Unix console or Mac terminal?
  • How to generate a random number in C++?
  • What is an optional value in Swift?
  • Callback functions in C++
  • Changing PowerShell's default output encoding to UTF-8
  • Running shell command and capturing the output
  • How do Mockito matchers work?
  • What are the currently supported CSS selectors…
  • commandButton/commandLink/ajax action/listener…
  • What is the scope of variables in JavaScript?
  • What does a "Cannot find symbol" or "Cannot resolve…
  • What does "Could not find or load main class" mean?
  • Understanding PrimeFaces process/update and JSF…
  • Why do git fetch origin and git fetch : behave differently?
  • What is the reason for the error message "System…
  • Why do I have to "git push --set-upstream origin "?
  • SQL query return data from multiple tables
  • Is it possible to apply CSS to half of a character?
  • What does this symbol mean in JavaScript?
  • How can I extract embedded fonts from a PDF as valid…
  • What's the best way to get the last element of an…
  • Check number of arguments passed to a Bash script
  • Java Process with Input/Output Stream
  • Unexpected exit code when running a batch file from…
  • Why does C++ code for testing the Collatz conjecture…
  • How to detect if multiple keys are pressed at once…
  • How to use Servlets and Ajax?
  • Reference — What does this symbol mean in PHP?
  • How to use java.net.URLConnection to fire and handle…
  • In CSS Flexbox, why are there no "justify-items" and…
  • Why am I getting a nil pointer error depending on…
  • What is an IndexOutOfRangeException /…
  • Why doesn't the height of a container element…
  • Batch script: how to check for admin rights
  • Echo a blank (empty) line to the console from a…
  • Vue&TypeScript: how to avoid error TS2345 when…
  • CSS selector for first element with class
  • Why call git branch --unset-upstream to fixup?
  • How can I view the source code for a function?
  • Error Message : Cannot find or open the PDB file
  • How do I return the response from an asynchronous call?
  • performSelector may cause a leak because its…
  • How does the "this" keyword work?
  • Detect if Visual C++ Redistributable for Visual…
  • How to get $HOME directory of different user in bash script?
  • '' is not recognized as an internal or external…
  • problem with client server unix domain stream…
  • What is null in Java?
  • What are type hints in Python 3.5?
  • How can I use/create dynamic template to compile…
  • MySQL server has gone away - in exactly 60 seconds
  • How to write :hover condition for a:before and a:after?
  • What does if __name__ == "__main__": do?
  • Pandas how to split vlaues of every column based on colon
  • How to find out client ID of component for ajax…
  • What encoding/code page is cmd.exe using?
  • How to end C++ code
  • Java string to date conversion
  • ember: understand errors
  • Simple logical operators in Bash
  • Bash: Echoing a echo command with a variable in bash
  • Replacing a 32-bit loop counter with 64-bit…
  • How to recover stashed uncommitted changes
  • How to debug a bash script?
  • Where and why do I have to put the "template" and…
  • Handling errors with the (now default) Ember Data…
  • Windows git "warning: LF will be replaced by CRLF",…
  • How is Perl's @INC constructed? (aka What are all…
  • Logging best practices
  • C# Only allow one class to call a different class's…
  • How to create a temporary table in SSIS control flow…
  • Get operating system info
  • Iterator invalidation rules

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How do I resolve “HTTP Error 500.19 – Internal Server Error” on IIS7.0

Next Post:

Append integer to beginning of list in Python

Leave a Reply Cancel reply

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

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error