当执行包含日志记录的python脚本时,popen返回错误

时间:2019-07-07 20:50:28

标签: python logging subprocess

我有2个python脚本,其中1个正在使用子进程执行另一个,请参见下文:

main.py

import subprocess

command = ['python', 'logging_test.py']
proc1 = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

out, err = proc1.communicate()

print('Output returned from command: {}'.format(out))
print('Error returned from command: {}'.format(err))

logging_test.py

import logging

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('log')
logger.info('hello')

运行main.py时,我将其作为输出:

Output returned from command:
Error returned from command: INFO:log:hello

我希望日志消息由stdout而不是stderr返回...有人知道为什么将其作为错误返回吗?

1 个答案:

答案 0 :(得分:1)