The requested program with subprocessor messages - the log does not print?

There is a problem with receiving messages from the program registrar if this program is called with a subprocess.

Here's the BooFoo.py program that uses the log to print messages in a file and console window:

import logging
LOG_FILENAME = 'example.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logger = logging.getLogger('main')
logger.addHandler(logging.StreamHandler())
print 'print foo'
logger.info('logger boo')

Here's the CallBooFoo.py program:

import subprocess
proc = subprocess.Popen(['python BooFoo.py'], bufsize=512, stdin = None, 
     stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell=True)
proc_out, proc_err = proc.communicate()
print proc_out

"logger boo" is not printed using CallBooFoo.py. Any idea how to fix this? Using os.system works, but is not a solution for other reasons.

+3
source share
1 answer

logging.StreamHandlerBy default, standard error is written, not standard error. You can change this to standard output with logging.StreamHandler(sys.stdout).

proc_err ( ) proc_out . .

stdout, stderr, :

proc = subprocess.Popen(['python BooFoo.py'], bufsize=512, stdin = None, 
     stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell=True)
proc_out, proc_err = proc.communicate()
print proc_out
+3

All Articles