在调用“ system”时抑制控制台。在C ++中 [英] Suppress console when calling "system" in C++
问题描述
我正在使用C ++中的 system
命令来调用某些外部程序,并且每当我使用它时,控制台窗口就会在命令完成后打开和关闭。
如何避免打开控制台窗口?如果解决方案可以独立于平台,我将很高兴。我也希望程序等待命令执行完毕。
听起来您正在使用Windows。 / p>
在Linux(通常是* nix)上,我将对 system
的调用替换为对<$的调用c $ c> fork 和 exec
。在Windows上,我认为Windows API中有某种生成新进程功能-请查阅文档。
在运行shell命令时, /或外部程序,您的程序很难与平台无关,因为它取决于所运行的命令和/或外部程序的平台。
I'm using the system
command in C++ to call some external program, and whenever I use it, a console window opens and closes after the command finishes.
How can I avoid the opening of a console window? I would be happy if the solution could be platform-independent. I would also like for my program to wait until the command is finished.
It sounds like you're using windows.
On Linux (and *nix in general), I'd replace the call to system
with calls to fork
and exec
, respectively. On windows, I think there is some kind of spawn-a-new-process function in the Windows API—consult the documentation.
When you're running shell commands and/or external programs, your program is hard to make platform-independent, as it will depend on the platform having the commands and/or external programs you're running.
这篇关于在调用“ system”时抑制控制台。在C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!