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

Emile van Sebille emile at fenx.com
Tue Jul 27 11:42:00 EDT 2010


On 7/27/2010 7:36 AM python at 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





More information about the Python-list mailing list