Suppress console when calling quot;systemquot; in C++(调用“系统时抑制控制台在 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.
推荐答案
听起来你在用windows.
It sounds like you're using windows.
在 Linux(和一般的 *nix)上,我会分别将对 system
的调用替换为对 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++ 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:调用“系统"时抑制控制台在 C++ 中


基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05