[python-win32] How to get PID from a Proces Handle ?
Metz, Bobby W, WWCS
bwmetz at att.com
Fri Oct 13 01:24:29 CEST 2006
You should consider using the new subprocess module. It provides both
phandle and pid. You can confirm this using EnumWindows and
win32process.GetWindowThreadProcessId. The value returned by .pid is
the same as that from GetWindowThreadProcessId. ._handle is the same as
that returned by spawnv, l, whatever.
process = subprocess.Popen(["c:\\windows\\notepad.exe",'',''])
print process.pid
print int(process._handle)
Bobby
-----Original Message-----
From: python-win32-bounces+bwmetz=att.com at python.org
[mailto:python-win32-bounces+bwmetz=att.com at python.org] On Behalf Of
Mark Hammond
Sent: Thursday, October 12, 2006 4:19 AM
To: 'Scott Hogsten'; python-win32 at python.org
Subject: Re: [python-win32] How to get PID from a Proces Handle ?
> I have some code that spawns processes using the "spawnv"
> command this returns a process handle.
> Can I use the process handle to retrieve the actual PID of
> the process ? This is part of a test harness
> and I need to be able have the actual PID to use against some output.
Good question! It's not immediately obvious how to do this simply, but
at a
pinch, maybe win32pdh or WMI could be used?
Other (more painful) option is to use CreateProcess to spawn your
process.
The best Python implemented example of how to do this I know of is at
http://svn.zope.org/*checkout*/Zope/trunk/lib/python/nt_svcutils/service
.py?
content-type=text%2Fplain - the main advantage is that you can redirect
the
output any place you like.
Hope that helps.
Mark
_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
More information about the Python-win32
mailing list