Logging output from python

Cameron Walsh cameron.walsh at gmail.com
Thu Dec 7 21:21:49 EST 2006


Barry wrote:
> Hi, guys
> 
> Basiclly, it is automated testing system. There is a main python script
> that handles the testing campagin. This main script will call another
> script that will in turn runs a few hundered individual python scripts.
> 
> 
> Here is my problem. I want to log everything displayed in the screen
> after I start the main python script. Things include unhandled
> exceptions , message from print statement and other sources.
> Basically, if it is displayed on the screen, I want to log it..
> 
> 
> It might not be a pythons specific problem. Does anyone know a small
> tool does that job?
> 
> 
> Thanks.
> 

If it's on linux you can just redirect the screen output to a file:

python initialfile.py 1>stdout.txt 2>stderr.txt

or if you want standard out and standard error to go to the same file:

python initialfile.py 1>output.txt 2>output.txt

or if you don't want to see anything on standard error:

python initialfile.py 1>output.txt 2>/dev/null


As for windows, I'll test it now...

It turns out you can at least redirect the output to a file, I'm not
sure what it does with standard error or even if it exists or not.

python initialfile.py > output.txt

should work.


Hope it helps,

Cameron.



More information about the Python-list mailing list