C#/Mono Console.In.ReadToEnd() 停止进程

标签 c# linux mono console

如果我有以下代码:

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 后不会停止?

最佳答案

我想通了。

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

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

有效。

关于C#/Mono Console.In.ReadToEnd() 停止进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4704020/

相关文章:

c# - 字典值作为不同的键

linux - 如何进行持续部署 - C++ on AWS

linux - 如何使我的程序可通过 linux 存储库安装(例如,使用 apt-get)?

c# - 在 mod_mono (3.12.1) 上运行的 XHR 代理中的 System.Threading.ThreadAbortException

c# - 将 Razor 页面呈现为字符串

c# - ComboBox 不会失去焦点

c# - 集合尚未初始化

linux - 如何使用 bash 中程序的输出重命名文件?

ubuntu - 在 mono/Ubuntu 上构建 SLN

f# - 平台调用 F# 回调函数