【发布时间】:2019-03-25 08:01:34
【问题描述】:
我正在从我的 pyhton 程序调用 shell 脚本,并且 shell 脚本将 INFO 和 DEBUG 日志作为输出的一部分。 当我从 python 程序运行 shell 脚本时,我只能看到标准输出,但看不到作为 shell 脚本输出的 INFO 和 DEBUG 日志。
我的代码:
process = subprocess.Popen(['bash','/myshell_script.sh',env, params],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while (True):
retcode = process.poll() # returns None while subprocess is running
line = process.stdout.readline()
**print(line)**
if (retcode is not None):
break
在这里,当我打印 shell 脚本输出时,我只能看到部分输出,看不到像 '18/10/20 11:24:55 INFO test test' 这样的输出(即 shell 脚本输出)
有人可以帮我提供一些信息,我怎样才能获得所有的 shell 脚本输出。
【问题讨论】:
标签: python shell process subprocess