Logging output from python

B

Barry

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.
 
C

Cameron Walsh

Barry said:
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.
 
G

Gabriel Genellina

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..

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

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

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

It's the same syntax as noted for linux above. 1> is the same as > alone.

If ALL the testing is done on a single program (that is, no os.system
or spawn or subprocess...) then you could just replace sys.stdout and
sys.stderr with another open file (or file-like) object.


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
M

MRAB

Gabriel said:
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..

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

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

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

It's the same syntax as noted for linux above. 1> is the same as > alone.

If ALL the testing is done on a single program (that is, no os.system
or spawn or subprocess...) then you could just replace sys.stdout and
sys.stderr with another open file (or file-like) object.
Redirection in Windows is explained here:

http://www.microsoft.com/resources/.../all/proddocs/en-us/redirection.mspx?mfr=true
 
L

Leonhard Vogt

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

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

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.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
>type output.py
import sys

print 'This is print.'
sys.stdout.write('This is stdout.write()\n')
sys.stderr.write('This is stderr.write()\n')
>python output.py 1>stdout.txt 2>stderr.txt
>type stdout.txt
This is print.
This is stdout.write()
>type stderr.txt
This is stderr.write()

Seems on XP it works too.

Leonhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top