tags:

views:

87

answers:

4
A: 

You can try CreateProcess. Have a look here:

http://stackoverflow.com/questions/1597289/hide-console-in-c-system-function-win

Andy West
Yeah i know this, but i am looking for a simple solution, maybe just adding a disableXXX() function :)
ndemir
A: 

system() is a Unix-compatibility holdover. I believe it's implemented by executing an external shell, which itself opens a console window. If you want to execute a GUI program directly, you'll probably need to use the win32 CreateProcess() API (and variants) directly.

Andy Ross
I think you'll find that `system()` is required by the ISO standard, not merely a "holdover". Not that Microsoft cares about the standards of course.
paxdiablo
Same diff. Microsoft would like you to believe that large swaths of the ISO standard are "holdovers" and you should use their own routines instead. Look up "warning c4996" to see exhibit A.
T.E.D.
The *presence* of the `system()` function is part of the C standard. But it's behavior is entirely unspecified. It would be 100% conformant for MS to include a noop `system()`, or one that crashed. The fact that it tries to run a MS-DOS command line is absolutely a "holdover" feature intended to look like Unix. Any amount of standards pedantry notwithstanding.
Andy Ross
Well, now I'm going to be even *more* pedantic. It's behaviour *is* entirely specified, even if the specification is to say that it's implementation defined. That has very definite meaning in ISO (unlike 'undefined') inasmuch as the implementation *must* specify the behaviour. Nonetheless, I'm not going to downvote you since the second part of your answer is useful (and the first part, though I disagree with it, doesn't render it less useful).
paxdiablo
+2  A: 

CreateProcess() if you need a lot of control. ShellExecute() if you need a quick fix.

Seva Alekseyev
A: 

Others have mentioned using CreateProcess (presumably to redirect the output).

The general reason this happens is that the program you are running via "system" is a command-line program. If it is something you compile yourself, you can get rid of the console window by building it as a GUI program instead. You should be able to do this by including Windows.h and using WinMain() as your entry point instead of main()

T.E.D.