无法重定向输出消息在Windows命令提示符(cmd.exe) [英] unable to redirect output message in windows command prompt (cmd.exe)
问题描述
我尝试在Windows命令提示符下运行以下命令。
abc.exe> log.txt 2>& 1
pre>
我期望
abc.exe
的所有输出被定向到log .txt
,但它不工作,因为log.txt
为空。
但是,如果我只是执行
abc.exe
,输出会显示在Windows命令提示符下。
我不知道什么是这个应用程序(STDOUT或STDERR)使用的输出处理程序,但我想知道是否有一种方法来捕获所有的消息,而不管处理程序。
解决方案重定向到文件时控制台输出不可见的症状可能是由于缺少
flush()
写入标准输出的程序。但是,当程序退出(正常)或相应缓冲区填满并自动刷新时,输出应可见。I tried to run the following command in Windows command prompt.
abc.exe >log.txt 2>&1
I'm expecting all output from
abc.exe
to be directed tolog.txt
, but it doesn't work, as thelog.txt
is empty.However, if I just execute
abc.exe
, the output is showing up in Windows command prompt.I'm not sure what is the output handler used by this application (STDOUT or STDERR), but I'm wondering is there a way to capture all messages regardless of the handler.
解决方案The symptom that console output is not visible when redirected to a file can be due to a missing
flush()
in the program that writes to the standard output. However, the output should be visible when the program exits (gracefully) or when the respective buffer fills up and is flushed automatically.这篇关于无法重定向输出消息在Windows命令提示符(cmd.exe)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!