output to console and to multiple files

Bart Ogryczak B.Ogryczak at gmail.com
Fri Feb 16 12:04:33 EST 2007


On Feb 14, 11:28 pm, "nathan.sh... at gmail.com" <nathan.sh... at gmail.com>
wrote:
> Hello,
>
> I searched on Google and in this Google Group, but did not find any
> solution to my problem.
>
> I'm looking for a way to output stdout/stderr (from a subprocess or
> spawn) to screen and to at least two different files.
>
> eg.
> stdout/stderr -> screen
> stdout -> log.out
> stderr -> log.err
>
> and if possible
> stdout/stderr -> screen and log.txt
>
> 3 files from stdout/stderr

I'd derive a class from file, overwrite it's write() method to send a
copy to the log, and then assign sys.stdout = newFile(sys.stdout).
Same for stderr.








More information about the Python-list mailing list