how to start a process and get it's pid?
Fredrik Lundh
fredrik at pythonware.com
Fri Nov 11 08:10:02 EST 2005
Daniel Crespo wrote:
>> >>> os.spawnl(os.P_NOWAIT, "c:/windows/notepad.exe")
>> 1944
>
> I don't get the correct PID.
>
> When I do os.spawnl(os.P_NOWAIT, "c:/windows/notepad.exe")
> I get 168 (for example), while in the tasklist appears notepad.exe with
> the 2476 PID.
>
> Why?
not sure, but the return value looks like a PID, so maybe you're seeing the
PID for the cmd.exe instance used to run the program. or something.
try this instead:
>>> import subprocess
>>> p = subprocess.Popen("c:/windows/notepad.exe")
>>> p.pid
1948
</F>
More information about the Python-list
mailing list