python subprocess
时间:2014-05-07 22:30:17
收藏:0
阅读:504
def getResult(cmd, timeout=2): #命令超时时间 deadline = time.time() + timeout r = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) while time.time() < deadline and r.poll() is None: time.sleep(0.1) if r.poll() is None: #检查子进程 r.kill() r.wait() return ‘‘ r.wait() r = r.stdout.read().strip() return r
评论(0)