为什么某些 cmd 启动的进程在输出重定向时会阻止/缓冲输出?

发布于 2024-08-24 15:03:03 字数 749 浏览 3 评论 0原文

为什么在我的 Windows 机器上的命令行启动的某些进程在重定向时会阻止/缓冲其整个输出,而其他进程则不会?

示例:tracert 在写入时不会阻止/缓冲输出。如果执行:

tracert ponyoverflow.com > output.txt

...output.txt 文件会随着时间的推移而增长。这完全是我所期望的事情的表现。

但是,我正在尝试使用潜在供应商的软件产品(iSpring SDK,如果您必须知道)并且它似乎会缓冲完整的输出,直到该过程完成。我感到困惑的是,当这个软件在命令行运行时,输出是零散的、逐行的,正如预期的那样。

为什么使用和不使用输出重定向调用它之间的行为存在差异?

跟进其他问题

  • 这是 Windows 命令行编程领域的常见和/或标准吗?
  • 我能做些什么来获取
  • 如何准确地与 iSpring 人员沟通(用 Windows 程序员的话说),我认为他们的软件应该如何在命令行上运行?

我不确定它有多重要,但我的所有这些实验都是在 64 位 Windows 7 Home Premium 计算机上进行的。

Why do some processes started at the command line on my Windows machine block/buffer their entire output if it is redirected and others not?

Example: tracert does not block/buffer output as it is written. If one executes:

tracert ponyoverflow.com > output.txt

...the output.txt file grows over time. This is completely how I would expect things to behave.

But, I'm trying to work with a potential vendor's software product (iSpring SDK, if you must know) and it seems to buffer the complete output until the process has finished. What I find confusing is that when this software is run at the command line the output comes piecemeal, line-by-line, as expected.

Why is there a difference in behavior between calling it with and without output redirection?

Follow up miscellaneous questions:

  • Is this common and/or standard in the world of Windows command line programming?
  • Is there anything I can do to grab the
  • How do I communicate exactly, in Windows programmer parlance, to iSpring folks how I think their software should behave at the command line?

I'm not sure how important it is, but all this experimentation of mine is happening on a 64-bit Windows 7 Home Premium machine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纸伞微斜 2024-08-31 15:03:03

(iSpring 的工作人员对我的请求的响应速度比我想象的要快得多。点对点。下面是他们对“原因”的回答。)

默认情况下,C++ 中的标准输出是缓冲的。缓冲区大小约为4KB。当应用程序完成时,缓冲区将被刷新。当标准输出与控制台连接时,写入 stdout 的数据不会被缓冲。

(The folks at iSpring were much quicker responding to me requests than I could have dreamed. Spot on. Here is their answer to 'why' below.)

Standard output in C++ is buffered by default. The buffer size is about 4KB. The buffer is flushed when the application finishes. Data written to stdout are not buffered when standard output is connected with a console.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文