21

What are the default values that can be passed to Environment.Exit method and what is the meaning to each of the code?

Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
J P
  • 272
  • 1
  • 2
  • 11
  • Also see [how-do-i-specify-the-exit-code-of-a-console-application-in-net](http://stackoverflow.com/questions/155610/how-do-i-specify-the-exit-code-of-a-console-application-in-net) – nawfal Jan 10 '14 at 10:25

3 Answers3

25

0 is success, anything else indicates an error. There isn't a standard.

Some programs try to meet conventions. Here's Microsoft's conventions. http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
2

The value passed are the exit code. By convention, 0 is success and anything else indicates an error. It's pretty much up to you to give semantic meaning to the different error codes.

soren.enemaerke
  • 4,770
  • 5
  • 53
  • 80
1

There is no predefined meaning of the exit code.

However, traditionally exit code 0 means success, and exit code > 0 means failure. Many applications assign some meanings to exit codes > 0, so the scripts can take advantage of this; the meanings are reflected in the application's documentation.

Some application follow the scheme "bigger value means graver mistake", some allow treating the exit code as a bit set, but most applications just define their own list of codes.

The exit codes < 0 are pretty uncommon.

Vlad
  • 35,022
  • 6
  • 77
  • 199