Hiding the DOS console on a console application on Windows

Bengt Richter bokr at oz.net
Sat Jan 26 05:43:53 EST 2002


On Fri, 25 Jan 2002 16:42:04 +0100, "Eric Brunel" <eric.brunel at pragmadev.com> wrote:

>Hi all,
>
>We've got a problem for which we were unable to find a solution: we have an
>Windows application that communicates with a console application and that
You don't say what the app to console realtionship is. Are they independent,
and one finds the other by various magic, or does one start the other?

>needs to occasionally send it a Ctrl-Break. The only way we found to do that
>was to use the Windows function "GenerateConsoleCtrlEvent" via an extension
>module. Problem: this function only works if the parent and child processes
>share the same console, so our application has to be run or built as a
>console application.
I'm sure you can build a straight windows gui app, and call AllocConsole() in
the win32 API to pop up an associated console window if you want one. You
don't have to build as a console app. Just do the AllocConsole() call when
you want a console window.

(It's great for debugging, since IIRC a single call sets it up ready to catch
print statement output that doesn't interfere with your windows GUI app, among
other things.) It's not clear to me exactly what you are doing, but read about
AllocConsole() and associated functions. It should help. Also, if you put
AllocConsole() in various paths, it doesn't matter if it gets called twice or
more. All but the first are ignored (again IIRC), so you get a console when
you first need it and not before (maybe not at all if you bypass all the calls).

>...] That means a start-up script with a .py extension (no
>.pyw, or it doesn't work), or a build without the option suppressing the
>console (e.g., no '--noconsole' option with Gordon McMillan's installer).
>However, our application has a GUI of its own, and we need to get rid of the
>DOS console that opens automatically when our script is run. Does anybody
>know a means to hide this console? We understand that this window has to be
>created, but we just don't want to see it...
>
>Our application uses Python 2.1.1 with a Tkinter GUI under Windows2k.
>
It's not as simple as just using pythonw.exe in place of python.exe, is it?
See if the discussion at
    http://www.onlamp.com/pub/a/python/excerpts/chpt20/?page=2
helps.

Regards,
Bengt Richter




More information about the Python-list mailing list