我试图运行控制台应用程序并读/写它的标准I/O。问题是,当这个应用程序通过WriteFile(GetStdHandle(...))写入输出时,我用管道上的ReadFile成功读取了它的输入。fprintf vs WriteFile写入管道:无法从所有管道读取
当目标应用程序使用fprintf时,ReadFile会阻止,直到目标应用程序退出,在这种情况下,它会一次返回整个输出。当目标应用程序阻塞(比如说,通过fgets())时,ReadFile块。
我正在使用标准管道重定向:http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx。
为什么这种奇怪的行为,我如何解决它?
Dup of http://stackoverflow.com/questions/1716296/why-does-printf-not-flush-after-the-call-unless-a-newline-is-in-the-format-strin –