I tried a bunch of stuff yesterday but couldn't get a good solution. It doesn't appear that MS gives a good way for a process to return it's PID. I ended up wrapping the program under test in C and using that to dump the PID to disk.
Scott ----- Original Message ---- From: Mark Hammond <[EMAIL PROTECTED]> To: Scott Hogsten <[EMAIL PROTECTED]>; [email protected] Sent: Thursday, October 12, 2006 7:18:34 AM 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 [email protected] http://mail.python.org/mailman/listinfo/python-win32
