Skip to content Skip to sidebar Skip to footer

Program Called With Subprocess - Logger Messages Are Not Printed?

there's a problem getting messages from a program's logger, if this program is called with subprocess. Here's the program BooFoo.py that uses logger to print messages to a file and

Solution 1:

logging.StreamHandler defaults to writing to standard error, not standard output. You can change this to standard output by using logging.StreamHandler(sys.stdout) instead.

You can also keep your code as is, and print the value of proc_err instead of (or in addition to) proc_out in the calling process. This will show the standard error of the child process.

If you need to see both stdout and stderr mixed together, you can change the calling process to:

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

Post a Comment for "Program Called With Subprocess - Logger Messages Are Not Printed?"