Disable Console Output from External Program (C++)

做~自己de王妃 提交于 2019-12-11 04:50:19

问题


My code (a simple console application) calls an external program (also a console application). This program spits out many things to the console, which significantly increases runtime when running in batch mode with 10,000+ iterations.

I've tried several ways to disable the output:

  1. Redirecting cout and cerr to fout -> obviously works on disabling couts in the current/local program, but doesn't disable anything from an external .exe.

  2. Some sources have suggested system("cls"), but all that does is clear the screen after the text has been displayed. This adds even more time.

  3. Another suggestion was to hide the console window, but the program still writes to the hidden console, so the entire process still takes more or less the same time.

It seems the only way left is to dig inside the external program's source code and disable all the write commands or redirect it to dev/null or something.

Is there a way to disable a program's write to console commands without having to alter the source code and recompile?

Many thanks!


回答1:


system( "theExternalProgram >nul 2>nul" );


来源:https://stackoverflow.com/questions/26606003/disable-console-output-from-external-program-c

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