python: run a process with timeout and capture stdout, stderr and exit status [duplicate]
Possible Duplicate: subprocess with timeout What is the easiest way to do the following in Python: Run an external process Capture stdout in a string, stderr, and exit status Set a timeout. I would like something like this: import proc try: status, stdout, stderr = proc.run(["ls", "-l"], timeout=10) except proc.Timeout: print "failed" I hate doing the work by myself. Just copy this into your proc.py module. import subprocess import time import sys class Timeout(Exception): pass def run(command, timeout=10): proc = subprocess.Popen(command, bufsize=0, stdout=subprocess.PIPE, stderr=subprocess