What is equivalent to EXIT_SUCCESS and EXIT_FAILURE in C #?

I am starting a process and want to check its exit code for success or failure.

Process myProcess = new Process();

myProcess.Start();

myProcess.WaitForExit();

// What should i put instead of EXIT_SUCCESS ?
if (myProcess.ExitCode == EXIT_SUCCESS) 
{
  // Do something
}

EXIT_SUCCESSdoesn't seem to exist, is there an equivalent or canonical way in C # to just check for zero?

+4
source share
3 answers

From C / C ++ code, they are typically defined as constants in some include header that uses them. So you usually have something like this:

#define EXIT_SUCCESS 0

. , " " - , , . # , :

private const int EXIT_SUCCESS = 0

. ,

if (myProcess.ExitCode == EXIT_SUCCESS) 
{
  // Do something
}
+2

System Error Codes MSDN:

ERROR_SUCCESS
    0 (0x0)        .

. #, Windows.

, // :

, Windows, .

+7

Before checking ExitCode, you must first check the HasExited property. Otherwise, it will throw an exception.

if (myProcess.HasExited) {
  //then check exit code
}

Like @DalmTo, exit codes are application dependent. But by convention, a value of zero equals the equivalent of EXIT_SUCCESS.

0
source

All Articles