基于此 Stackoverflow问题,我正在尝试通过 Python 获取进程的输出。
这里有代码:
from subprocess import Popen, PIPE
connection_string = "yowsup-cli demos --yowsup --config config"
popen_parameters = connection_string.split(" ")
proc = Popen(popen_parameters, stdout=PIPE, stderr=PIPE)
while True:
line = proc.stdout.readline()
if line != '':
#the real code does filtering here
print "Result:", line.rstrip()
proc.stdout.flush()
不幸的是,没有任何东西被归还。顺便说一句,我需要与发送和接收数据的进程进行交互。我怎样才能完成这项工作?
谢谢!
最佳答案
while 循环没有条件退出,即使命令输出已发送。 试试这个:
if line != '':
#the real code does filtering here
print "Result:", line.rstrip()
else:
break
关于python - 为什么我无法从通过 Python 脚本调用的进程中获取输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29183396/