Re: Console window opening during system() call inside GTK User Interface



2008/1/15  <vijayasarathy setsindia net>:
I have a GTK base GUI, which takes an exe as input[from a text box entry]
and passes it to a function in a library, where there is a system() call.
So, there is no direct system() call in the GTK call back or main function
itself, GTK simply passes values to the library function, which calls
system(). And here is where the console window pops up.

I spent some time looking into this recently when faced with a similar problem.

On *nix systems, there's no difference between a GUI program and a
command-line program (a GUI program is just a command-line program
that opens a window).

However, windows (for historical reasons) has both
IMAGE_SUBSYSTEM_WINDOWS_GUI and IMAGE_SUBSYSTEM_WINDOWS_CUI
executables (possible values for the "executable type" field in the
.exe).

The value of this field sets how windows starts the program: CUI
programs started from explorer get a command window showing input and
output which stays around for as long as the program is running, CUI
programs started from cmd.exe use that window for input and output and
block cmd.exe until they finish. CUI programs started from system()
get a console window and block. GUI programs get no command windows
when started from explorer, when started from cmd.exe or from system()
they don't block, and they get no IO either (I hope I have all that
right).

Your problem is that you are trying to run a CUI program without a
console window via system() and it's just not possible. You need to
write a "wrapper" program, tagged as GUI, which starts the CUI program
for you without a console window. Apparently this is quite a commmon
thing for windows programmers to do: a friend sent me sample one, I
can fwd itto you when I'm back at work tomorrow.

There will be a further problem though: your system() call will no
longer block and you'll need to find some other way to wait for the
child program to finish.

As Allin said, don't use system() on windows if you can possibly avoid it.

John



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]