开发者

ExitCode of -1 returned to C#

开发者 https://www.devze.com 2023-01-20 22:27 出处:网络
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 trackin

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开发者_如何学Python 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号