[Python-Dev] Console vs. GUI applications

Moore, Paul Paul.Moore at atosorigin.com
Thu Sep 9 10:56:00 CEST 2004


From: "Martin v. Löwis"
>Thomas Heller wrote:
>> It seems to be a flag in the exe header.  A quick google search turned
>> up this:
>> 
>> http://www.codeguru.com/Cpp/W-P/system/misc/article.php/c2897/
>
> Sure. However, if I do
>
> foo.py
>
> then some part of the system must determine that python.exe is
> to be invoked, and then must determine that this is a console
> binary. Does that all happen in cmd.exe?

I believe so. The relevant Windows API call is CreateProcess, which
only handles EXEs (and maybe some obscure cases like COM and PIF files).
Everything else gets done in user code (in this case CMD.EXE).

So CMD.EXE runs CreateProcess on your launcher.exe. CreateProcess checks
a flag (the "subsystem") in the executable header, and acts dependent on
that. For a "console" executable, it leaves the new process attached to
the current console (the one CMD.EXE is using) and for a "windows"
executable, it detaches the process from any console. (Default behaviour
- there are flags which can affect this).

I can't work out how CMD.EXE "knows" to wait for a child process to release
the console (immediately for a windows process, when it terminates for a
console process) but clearly it does... A test shows that it *is* possible
for two console processes to share the console. The result is an unusable
mess, though, so we should be glad cmd.exe does avoid this :-)

Paul.


__________________________________________________________________________
This e-mail and the documents attached are confidential and intended 
solely for the addressee; it may also be privileged. If you receive this 
e-mail in error, please notify the sender immediately and destroy it.
As its integrity cannot be secured on the Internet, the Atos Origin group 
liability cannot be triggered for the message content. Although the 
sender endeavours to maintain a computer virus-free network, the sender 
does not warrant that this transmission is virus-free and will not be 
liable for any damages resulting from any virus transmitted.
__________________________________________________________________________


More information about the Python-Dev mailing list