Get the pid of a os.startfile(filename)

Do Re Mi chel La Si Do enleverlesO.OmcO at OmclaveauO.com
Tue Nov 8 21:08:01 CET 2005


Hi !

With W2K or WXP :

        tasklist /FI "IMAGENAME eq exename.exe"


And, with Python, how capture this information :

def findPID(exename):
    import os
    a = os.popen4('tasklist /FI "IMAGENAME eq '+exename+'"')
    a[0].flush()
    try:
        info=a[1].readlines()[3].split()
    except:
        info=[exename,"NotFound"]
    return (info[0],info[1])

soft,pid=findPID("pythonw.exe")
print soft,' --> ',pid



@-salutations

Michel Claveau







More information about the Python-list mailing list