Suppress console when calling “system” in C++

前端 未结 5 1736
灰色年华
灰色年华 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:09

    This is probably the easiest and maybe the best way, this will also make it so that your program doesn't freeze while running this command. At first don't forget to include the Windows header using;

    #include 
    

    Then you need to use the following function to run your command;

    WinExec("your command", SW_HIDE); 
    

    Note; The WinExec method has been deprecated for over a decade. It still works fine today though. You shouldn't use this method if not required.

    ... instead of the way you don't want to use;

    system("your command");
    

提交回复
热议问题