Python 2.7子进程:获取stdout,设置超时并使用env变量

时间:2016-06-22 22:05:57

标签: python-2.7 shell timeout subprocess stdout

我使用subprocess.Popen()启动子流程并使用communicate()方法获取输出。我试图实现超时约。如下(我目前没有实际的副本):

while p.poll() != 0 and theres_still_time():
    sleep(1)
p.kill()
out,err=p.communicate()

p.communicate()之后拨打p.kill()看起来很奇怪。虽然它不会引发错误,但它似乎并没有按时实际关闭该过程。

有办法:

  • 获取stdout和stderr
  • 设置超时
  • 从shell执行

所有在Windows 8.1的python 2.7中的相同进程?

如果解决方案可以使用环境变量(特别是路径变量),那么从shell执行是不必要的。

0 个答案:

没有答案