os.system and loggers

Tim jtim.arnold at gmail.com
Fri Jan 7 11:24:01 EST 2011


hi, I'm using a 3rd-party python program that uses the python logging
facility and also makes calls to os.system. I'm trying to capture its
output to a file.

In my own code, I've taken control of the loggers that are setup in
the other program by removing its StreamHandler and replacing with
FileHander. But when it comes to the call to os.system I'm at a loss.

I want to capture the stdout from that os.system call in my
FileHandler. I thought this might work, before I call the other
program's class/method:
sys.stdout = getLogger('status').handlers[0].stream

but no dice. Is there any clean way to get what I want? If not, I
guess I'll override the other method with my own, but it will
basically be a bunch of code copied with os.sytem replaced with
subprocess, using getLogger('status').handlers[0].stream for stdout/
stderr.

thanks,
--Tim Arnold



More information about the Python-list mailing list