我手头有点紧:)
我发现了一个非常奇怪的行为,我不知道是什么原因造成的。
它与 C# Visual studio 2008 中的控制台登录有关
例如,命令行的正常行为是:
1) If i use the "dir" command i see the contents of the directory
2) If i use "dir > 1.txt" i get the contents of the directory in the 1.txt file.
所以这是正常行为并且有效。现在回到我的问题。
在我使用的 C# 应用程序中,我有一个测试列表,当我从命令行使用我的应用程序时,我想列出它们。所以我有:
Console.WriteLine("Start running " + sn);
当我正常运行应用程序时的结果是:(我发送的命令)
Application.exe -run 1.test,2.test,3.test
输出:
Start running 1.test
Start running 2.test
Start running 3.test
但是如果我使用这个命令:
Application.exe -run 1.test,2.test,3.test > 1.txt
三个开始运行的命令从标准输出中消失,但 1.txt 为空白。
我不知道响应的去向,我无法记录响应,但我可以直观地看到它。但是当我将 STDOUT 重定向到日志时,它既不存在于视觉上也不存在于日志中。
有人知道吗?
最佳答案
文件的输出被缓冲。在最坏的情况下,内容将在应用程序完成后保存。要强制刷新缓冲区,您可以调用:
Console.Out.Flush();
关于c# - Console.Writeline C# - 记录时丢失 STDOUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16791167/