我有两个python脚本,其中一个使用子流程执行另一个,请参见以下内容:
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返回。。。有人知道为什么它会作为错误返回吗
basicConfig
,除其他外,provides a ^{相关问题 更多 >
编程相关推荐