ExitCode 为 -1 返回到 C#

发布于 2024-09-28 13:34:59 字数 382 浏览 0 评论 0原文

在我的 C# 应用程序中,我使用 .NET Process 类启动一个程序。有时,程序完成后,Process.ExitCode 为-1。这是一个很大的程序,我无法追踪用 -1 调用“exit”的位置。

事实上,我不明白程序如何返回退出代码 -1。我创建了一个仅从 main' 返回的 C 程序。无论我从 C 返回什么值,在 C# 中,我都会看到该值 mod 256。如果 C 程序返回 -1,在 C# 中,我会看到 255。从 Cygwin bash shell,echo $?'在这种情况下也显示 255。

原始程序(显示 ExitCode 为 -1 的程序)是用 OCaml 编写的。我认为这并不重要。

那么什么会导致 Process.ExitCode 显示为 -1 呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雾里花 2024-10-05 13:34:59

此代码生成退出代码 -1:

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

换句话说:当进程意外中止时,您将得到 -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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文