我从我的pyhton程序调用shell脚本,shell脚本有信息&调试日志作为输出的一部分。当我从python程序运行shell脚本时,我只能看到标准输出,但看不到shell脚本输出的信息和调试日志。
我的代码:
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‘(即shell脚本输出)。
有人能帮我提供一些信息,如何才能得到所有的shell脚本输出。
发布于 2018-10-20 19:19:14
看起来,您的脚本正在将INFO和DEBUG日志发送到stderr。您可以尝试删除stderr=subprocess.PIPE,查看输出是否出现在终端中。
如果您真的需要subprocess.PIPE for stderr,假设您想从stderr获取stderr输出,则需要调用process.communicate()查看更多信息Popen.communicate
https://stackoverflow.com/questions/52909115
复制相似问题