Suppress console when calling “system” in C++

前端 未结 5 1731
灰色年华
灰色年华 2020-12-17 16:57

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.

5条回答
  •  爱一瞬间的悲伤
    2020-12-17 17:26

    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.

提交回复
热议问题