c# - Console.Writeline C# - 记录时丢失 STDOUT

标签 c# console stdout

我手头有点紧:)

我发现了一个非常奇怪的行为,我不知道是什么原因造成的。

它与 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/

相关文章:

c# - 无法连接到任何指定的 MySQL 主机登录表单

c - 在 Windows 中获取终端大小?

javascript - 脱壳到 Node 时保留输出颜色

c# - 为什么我不能将 DateTime[] 转换为 object[]?

c# - 在 C# 中使用 System.ComponentModel.BackgroundWorker 和 lambda 的最佳方式

c# - 如何使我的所有输出以及我的光标都集中在 Visual Studios 中?

perl - 如何在 Perl 中找到进程 STDOUT 的当前值?

go - 连续读取 exec.Cmd 输出

c# - 异步/等待内存缓存的线程安全

r - 在 Shiny 中使用 readlines(prompt = )