views:

139

answers:

3

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.

+1  A: 
Jonas Kölker
Generally speaking, you are right about programs being platform-dependent when using shell commands. However, in this case, I'm making sure that the external program is installed on the machine I'm using. It's not a simple shell command. Regarding your answer - It's possible to use CreateProcess for windows and fork+exec for unix, but I was hoping to solve this more elegantly.
Dana
what's not elegant about CreateProcess/fork+exec? If you wrap it in a nice class, you have a very elegant way to start processes, plus you can easily add options like redirecting output/input ect.
stijn
A: 

exec() looks quite platform independant as it is POSIX. On windows, it's _exec() while it's exec() on unix: See http://msdn.microsoft.com/en-us/library/431x4c1w%28VS.71%29.aspx

Bluebird75
A: 

Errm. CreateProcess or ShellExecute.

Alex