Doing a ps in windows.. (Is application XYZZY running?)

Bengt Richter bokr at oz.net
Mon Mar 25 20:15:21 EST 2002


On Mon, 25 Mar 2002 20:54:19 GMT, Andrew Markebo <flognat at flognat.myip.org> wrote:

>*blush* yeah I know.. not really.. here, only almost :-)
>
>I have the windows-compiled python 2.2, and I would like to see if
>Opera or Netscape is running on my computer (poor sod, running Win2k,
>XP or 98).. How do I do this, I suppose I could use something in the
>win32api, but what is something.. :-) ??
>
>On unix I do "ps -ef | grep netscape" ;-)
>
There are correpsonding things on NT4 at least:

 >>> def pidmatch(x):
 ...     import os
 ...     pidlines = os.popen('pstat | findstr/R/I "^pid.*'+x+'"').readlines()
 ...     return [line.split()[-1] for line in pidlines]
 ...
 >>> pidmatch('iexplore')
 []
 >>> pidmatch('netscape')
 ['netscape.exe']
 >>> pidmatch('sys')
 ['System', 'systray.exe']

You could read the whole pstat result and do the grep/findstr function
in pidmatch, but I was inspired by your unix example ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list