Windows console output not going to stdout nor stderr

烈酒焚心 提交于 2019-12-23 04:43:22

问题


Is it possible for any windows console app to output to console, while not outputting to stdout nor stderr? If yes - how to capture/redirect the output?

I have a third party console app that I used to start from my C# app and redirect its stdandard error and output and read them from within my app. With an upgrade of this 3rd party app this approach stopped working. During investigation I found out that while it outputs to console; redirecting stderr to file caused it not to output to console (expected), but file was empty (very unexpected):

CNTK.exe 1>out.txt 2>err.txt

No content in out.txt nor err.txt

Without redirection the app outputs the basic diagnostic info into the console.

Based on the source code it uses fprintf(stderr, ...) for outputing - so I'm quite puzzled why it's not redirectable. Even regardless of the app in question or how it outputs to console - I'm quite puzzled how it is even possible for the app to output to console without user ability to redirect the output to pipes.

Edit: seems to be caused by a bug in older version of MS cpp runtime: https://connect.microsoft.com/VisualStudio/feedback/details/1441507/stdout-and-stderr-not-always-flushed-upon-process-exit 3rd party app is linked against VS 2013 runtime and codepath executed by my test was not explicitly calling fflush(stderr); prior exiting (despite this should not be needed, but it is due to the bug)

来源:https://stackoverflow.com/questions/41556226/windows-console-output-not-going-to-stdout-nor-stderr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!