gpt4 book ai didi

c# - 如何从 C# 写入 cygwin 管道

转载 作者:太空狗 更新时间:2023-10-29 19:47:38 26 4
gpt4 key购买 nike

我想创建一个可以在带有“tail -f”的 cygwin 管道中使用的 C# 应用程序。

tail -f SomeFile | MyCSharpApp

我可以看到(通过调试)我能够正确读取标准输入,但没有任何内容被写回 cygwin 终端窗口。

但是,

tail -n10 SomeFile | MyCSharpApp

完美运行。

class Program
{
static void Main(string[] args)
{

string s;
while ((s = Console.ReadLine()) != null)
{
//Potentially process s here
Console.WriteLine(s);
}
}
}

最佳答案

尚不清楚 SomeFile 发生了什么。 tail -f SomeFile 打开 SomeFile 文件描述符并监视它。如果描述符以某种方式更改,例如,您在记事本中打开文件并单击“保存”,则不会监视任何内容。发生这种情况是因为记事本删除了该文件并写入了同名的新文件。我建议尝试 tail -F SomeFile-F 重新打开文件描述符。

关于c# - 如何从 C# 写入 cygwin 管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56223137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com