我想创建可在带有“ tail -f”的cygwin管道中使用的ac#应用程序。
即
尾-f SomeFile | MyCSharpApp
我可以从调试中看到,我能够正确读取stdinput,但是什么都没有写回cygwin终端窗口。
然而,
尾-n10 SomeFile | MyCSharpApp
完美运作。
class Program
{
static void Main(string[] args)
{
string s;
while ((s = Console.ReadLine()) != null)
{
//Potentially process s here
Console.WriteLine(s);
}
}
}
Run Code Online (Sandbox Code Playgroud)
目前还不清楚 SomeFile 发生了什么。tail -f SomeFile打开 SomeFile 文件描述符并监视它。如果描述符以某种方式发生变化,例如,您在记事本中打开文件并单击“保存”,则不会监视任何内容。发生这种情况是因为记事本删除了该文件并写入了同名的新文件。我建议尝试一下tail -F SomeFile。-F重新打开文件描述符。