From: MrJean1 on
On Jul 27, 8:36 am, Tim Golden <m...(a)timgolden.me.uk> wrote:
> On 27/07/2010 15:58, Brian Curtin wrote:
>
> > On Tue, Jul 27, 2010 at 09:36,<pyt...(a)bdurham.com>  wrote:
>
> >> Windows: How can I detect whether a Python app/script is running in
> >> console/GUI mode? By app I mean a script compiled to an exe via py2exe or
> >> similar.
>
> >> Thank you,
> >> Malcolm
>
> > I don't remember much about py2exe, but you could check if
> > ``os.path.split(sys.executable)[1]`` equals pythonw.exe (typical for GUIs)
> > or just python.exe (regular console).
>
> Don't know whether it's foolproof, but I suspect that
> checking whether win32console.GetConsoleWindow ()
> returns zero is probably not a bad approach.
>
> TJG    

Executables built with py2exe have an attribute sys.frozen and its
value is 'console_exe' for console applications or 'windows_exe' for
GUI applications. See for example <http://www.py2exe.org/index.cgi/
Py2exeEnvironment>.

/Jean