469,602 Members | 1,794 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Logging output from python

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.

Dec 8 '06 #1
4 3718
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.
Dec 8 '06 #2
At Thursday 7/12/2006 23:21, Cameron Walsh wrote:
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. 1is 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
Dec 8 '06 #3

Gabriel Genellina wrote:
At Thursday 7/12/2006 23:21, Cameron Walsh wrote:
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. 1is 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/d....mspx?mfr=true

Dec 9 '06 #4
Cameron Walsh schrieb:
>
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.
>cmd
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
Dec 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Thomas Schulz | last post: by
6 posts views Thread by Eric DeWall | last post: by
1 post views Thread by jjesso | last post: by
1 post views Thread by Maksim Kasimov | last post: by
23 posts views Thread by Rotem | last post: by
12 posts views Thread by Eric S. Johansson | last post: by
4 posts views Thread by samwyse | last post: by
6 posts views Thread by Thomas Heller | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.