【发布时间】:2015-04-07 06:39:05
【问题描述】:
我有一个从 Python 脚本进行的系统调用。我想要一个计时器以及利用呼叫的输出。我可以一次做一个:使用subprocess.call() 实现一个计时器并使用subprocess.Popen() 检索输出。但是,我需要计时器和输出结果。
有什么办法可以做到吗?
以下代码给我一个Attribute error: 'int' object has no attribute 'stdout',因为subprocess.call 输出不是我需要使用的Popen 对象。
... Open file here ...
try:
result = subprocess.call(cmd, stdout=subprocess.PIPE, timeout=30)
out = result.stdout.read()
print (out)
except subprocess.TimeoutExpired as e:
print ("Timed out!")
... Write to file here ...
任何帮助将不胜感激。
【问题讨论】:
标签: python subprocess