Windows: How to detect whether a Python app/script is running in console/GUI mode?

2010-07-27 Thread python
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows: How to detect whether a Python app/script is running in console/GUI mode?

2010-07-27 Thread Brian Curtin
On Tue, Jul 27, 2010 at 09:36, pyt...@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).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows: How to detect whether a Python app/script is running in console/GUI mode?

2010-07-27 Thread Tim Golden

On 27/07/2010 15:58, Brian Curtin wrote:

On Tue, Jul 27, 2010 at 09:36,pyt...@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 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows: How to detect whether a Python app/script is running in console/GUI mode?

2010-07-27 Thread Emile van Sebille

On 7/27/2010 7:36 AM pyt...@bdurham.com said...

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.



Once you've got an exe, you'll need to know the name you're looking for. 
 There are several utilities available -- I use pslist from 
sysinternals, but there are others out there like process explorer, WMIC 
or tasklist.  You could translate the VB found at 
http://support.microsoft.com/kb/187913 and use win32.  You could program 
a pid file into your exe and check that.


One cheap trick is to create a file and keep it open while your process 
runs.  From the outside, if the file is missing or you can erase the 
file, you're process isn't active.  This relies on windows requiring 
exclusive access to delete a file which it does, and doesn't rely on the 
presence of a particular windows version or installation of a third 
party utility.


HTH,

Emile


--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows: How to detect whether a Python app/script is running in console/GUI mode?

2010-07-27 Thread MrJean1
On Jul 27, 8:36 am, Tim Golden m...@timgolden.me.uk wrote:
 On 27/07/2010 15:58, Brian Curtin wrote:

  On Tue, Jul 27, 2010 at 09:36,pyt...@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
-- 
http://mail.python.org/mailman/listinfo/python-list