Home > C#, C# Snippets > C#: Use exit code from application in Windows batch file (script)

C#: Use exit code from application in Windows batch file (script)

14:58

Marek Śliwiński Leave a comment Print This Post  (115) Go to comments

That’s pretty easy stuff if you know it already.

Take a look on example (TestApp.exe):

  static int Main(string[] args)
        {
            int myCodeNumber = 1;

            // Return some code number
            return myCodeNumber;
        }

and here it is how to catch it in Windows batch file (test.bat):

REM Run app which will return some code number
TestApp.exe

REM If returned code is not == 1 then "do something" else continue to NEXT section
if %errorlevel% NEQ 1 GOTO :NEXT
DO SOMETHING HERE

:NEXT
Share and Enjoy:
  • DotNetKicks
  • Digg
  • del.icio.us
  • Wikio IT
  • Google Bookmarks
  • Facebook
  • Print
Categories: C#, C# Snippets Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Subscribe without commenting