【问题标题】:C#/Mono Console.In.ReadToEnd() stopping processC#/Mono Console.In.ReadToEnd() 停止进程
【发布时间】:2011-01-16 05:41:50
【问题描述】:

如果我有以下代码:

namespace foo {
 public class FooClass {
  public static void Main (string[] argsRaw) {
   Console.WriteLine(Console.In.ReadToEnd());
  }
 }
}

我运行它,一旦到达流的末尾,进程就会停止。

输出:

(Text of my input stream)
[1]+  Stopped                 bin/Debug/foo.exe

如何让我的程序表现得更像 grep,在遇到 EOF 后不会停止?

【问题讨论】:

  • Logan:在 Linux 上可能是 Ctrl+D。
  • @Gabe 对。但在 Linux 上,Ctrl+Z 通常会暂停该进程。我想知道他是不是 Window 的移植者被绊倒了。
  • 实际上,我没有敲键。我正在转储一个文件作为输入... $ ./foo.exe

标签: c# linux mono console


【解决方案1】:

我想通了。

您需要确保 Main 的返回类型是 int。

namespace foo {
    public class FooClass {
        public static int Main (string[] argsRaw) {
            Console.WriteLine(Console.In.ReadToEnd());
            return 0;
        }
    }
}

工作。

【讨论】:

    猜你喜欢
    • 2018-10-23
    • 2020-12-18
    • 2020-01-12
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多