当呼叫“系统”时,抑制控制台在c ++ [英] Supress console when calling "system" in c++

查看:196
本文介绍了当呼叫“系统”时,抑制控制台在c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C ++中的 system 命令调用一些外部程序,每当我使用它时,控制台窗口在命令完成后打开并关闭。

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.

在Linux上(通常是* nix),我会替换 system c $ c> fork 和 exec 。在Windows上,我认为在Windows API中有某种类型的spawn-a-new-process函数,请参阅文档。

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.

当你运行shell命令和/或外部程序,您的程序很难使平台无关,因为它将取决于具有命令和/或您正在运行的外部程序的平台。

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.

这篇关于当呼叫“系统”时,抑制控制台在c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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