【发布时间】:2019-10-06 22:53:27
【问题描述】:
我想用“tail -f”创建一个可以在 cygwin 管道中使用的 c# 应用程序。
即
tail -f SomeFile | MyCSharpApp
我可以看到(通过调试)我能够正确读取 stdinput,但没有任何内容回写到 cygwin 终端窗口。
然而,
tail -n10 一些文件 | MyCSharpApp
完美运行。
class Program
{
static void Main(string[] args)
{
string s;
while ((s = Console.ReadLine()) != null)
{
//Potentially process s here
Console.WriteLine(s);
}
}
}
【问题讨论】:
-
所以这不是 C# 问题
-
@MarcoSalerno 我认为是。当我不在管道中包含我的应用程序时,tail -f 和 tail -n10 都可以工作。
-
Cygwin,呵呵,天啊哟。首先 Slurp 所有输入,这样您就不会在管道缓冲区大小上死锁。
-
@HansPassant 你能建议我如何在 Tail -f 连续的情况下做到这一点吗?
-
我对您帖子中的这句话感到困惑:“我可以看到(从调试中)我能够正确读取 stdinput,但没有任何内容回写到 cygwin 终端窗口。”当您说您能够正确读取标准输入时,您是什么意思? Console.ReadLine 是否返回信息?出于好奇,您是否尝试过 Console.Read 而不是 Console.ReadLine?