ocaml – ExitCode of -1 returned to C# – Education Career Blog

In my C# application, I’m firing up a program using the .NET Process class. Sometimes, after the program has finished, the Process.ExitCode is -1. It’s a large program, and I’m having trouble tracking down where `exit’ is called with -1.

In fact, I don’t see how it’s possible to have a program return an exit code of -1. I’ve created a C program that just returns from main'. Whatever value I return from C, in C#, I see that value mod 256. If the C program returns -1, in C#, I see 255. From a Cygwin bash shell,echo $?’ also shows 255 in that case.

The original program — the one that shows an ExitCode of -1 — is written in OCaml. I don’t think that should matter.

So what would cause Process.ExitCode to show up as -1?

,

This code produces an exit code of -1:

class Program
{
    static void Main(string args)
    {
        Process.GetCurrentProcess().Kill();
    }
}

In other words: when the process aborts unexpected, you get -1 as result. Maybe this helps.

Leave a Comment