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++ 中
基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 常量变量在标题中不起作用 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
