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++ 中


基础教程推荐
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01