Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress console when calling "system" in C++

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.

like image 919
Dana Avatar asked Nov 26 '09 09:11

Dana


1 Answers

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 <Windows.h>

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");
like image 106
Tim Visée Avatar answered Oct 14 '22 15:10

Tim Visée