禁用外部程序的控制台输出(C ++) [英] Disable Console Output from External Program (C++)

查看:117
本文介绍了禁用外部程序的控制台输出(C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码(一个简单的控制台应用程序)调用外部程序(也是控制台应用程序)。这个程序向控制台输出了很多东西,这在以10,000次迭代的批处理模式运行时显着增加了运行时间。

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. 将cout和cerr重定向到fout
    - >显然适用于禁用当前/本地程序中的cout,

  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.

某些来源已建议系统(cls),但所有这一切都会清除屏幕上的文本已显示。

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.

另一个建议是隐藏控制台窗口,但程序仍然写入隐藏的控制台,因此整个过程仍然需要更多

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.

似乎唯一的方法是挖掘外部程序的源代码,并禁用所有写入命令或将其重定向到dev / null或某事。

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?

非常感谢!

推荐答案

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

这篇关于禁用外部程序的控制台输出(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆