# run and or manage a subprocess with the python subprocess module def openProcess(pname): import subprocess exe = subprocess.Popen(pname) #print exe.pid exe.poll() # poll() will set returncode if exe.returncode is None: print 'process still running' exe.wait() # wait() will also update returncode # at this point the script will wait until the executable quits if exe.returncode is None: print 'process still running' else: print 'process execution is complete' if __name__ == '__main__': openProcess('notepad.exe') ##outputs: #process still running #process execution is complete
A python example based blog that shows how to accomplish python goals and how to correct python errors.
Showing posts with label poll. Show all posts
Showing posts with label poll. Show all posts
Wednesday, September 16, 2009
Python - run and manage a subprocess
Labels:
executable,
poll,
popen,
python,
returncode,
subprocess,
wait
Subscribe to:
Posts (Atom)