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


python subprocess,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!