3

I have a C# console application AAA.exe which can return an integer to indicate the result

static int Main(string[] args)
  {
    . . .
    if(case1)
       return -1;

    if(case2)
       Environment.Exit(1);

    return 0;
}

I will call AAA.exe in a batch file and need the return value

AAA.exe /p="param1"

My question is:

  1. how to get the return value of AAA.exe?
  2. is there any difference between return 0; and Environment.Exit(0); statements?
Carlos Liu
  • 2,348
  • 3
  • 37
  • 51

3 Answers3

8

You can use "errorlevel" in your batch file to get the returned value. More info here.

Foole
  • 4,754
  • 1
  • 26
  • 23
4

Is there any difference between return 0; and Environment.Exit(0); statements?

See this post

Community
  • 1
  • 1
dugas
  • 12,025
  • 3
  • 45
  • 51
0

The environmental variable %ERRORLEVEL% contains the return code of the last executed program or script.

By default, the way to check for the ERRORLEVEL is via the following code.

Syntax
IF %ERRORLEVEL% NEQ 0 ( 
   DO_Something 
)

Source: https://www.tutorialspoint.com/batch_script/batch_script_return_code.htm

YTG
  • 956
  • 2
  • 6
  • 19