【发布时间】:2019-11-17 10:37:34
【问题描述】:
我有 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
我希望日志消息由标准输出返回,而不是标准错误……有谁知道它为什么会作为错误返回?
【问题讨论】:
-
标准错误用于诊断和错误消息。
标签: python logging subprocess