[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Error messages when using the Console Module

peter

2/15/2008 1:59:00 PM

I am developing code using the effbot Console module, which gives
control over the Windows terminal settings. My problem is that while
this module redirects standard output to a new console window, it
seems to redirect standard error messages to a black hole. So when my
new code fails, I have no error messages to assist in diagnosing the
problem. At times I have been reduced to writing new code a line at a
time!

I'm sure there is an easy solution to this problem, but googling has
yet to reveal it. Can anyone help?

Peter
3 Answers

Christian Heimes

2/15/2008 2:13:00 PM

0

peter wrote:
> I am developing code using the effbot Console module, which gives
> control over the Windows terminal settings. My problem is that while
> this module redirects standard output to a new console window, it
> seems to redirect standard error messages to a black hole. So when my
> new code fails, I have no error messages to assist in diagnosing the
> problem. At times I have been reduced to writing new code a line at a
> time!

Windows GUI apps don't have valid standard streams. stdin, stdout and
stderr aren't connected and their fileno is -1. I guess you have to
connect the streams manually when you create a console window. C code
can use freopen() but I don't know how to properly redirect the streams
from Python.

MSDN has probably some docs for you.

Christian

Gabriel Genellina

2/16/2008 12:56:00 AM

0

En Fri, 15 Feb 2008 11:59:07 -0200, peter <peter.mosley@talk21.com>
escribió:

> I am developing code using the effbot Console module, which gives
> control over the Windows terminal settings. My problem is that while
> this module redirects standard output to a new console window, it
> seems to redirect standard error messages to a black hole. So when my
> new code fails, I have no error messages to assist in diagnosing the
> problem. At times I have been reduced to writing new code a line at a
> time!

The Console module doesn't redirect standard output, AFAIK. You can do
that either from inside the script or when invoking it from the command
line:

import sys
sys.stdout = open("stdout.log","w")
sys.stderr = open("stderr.log","w")
print "This goes to stdout"
print >>sys.stderr, "This goes to stderr"

or:

python yourscript.py >stdout.log 2>stderr.log

To redirect all output to the same file, you can use

sys.stdout = sys.stderr = open("output.log","w")

or:
python yourscript.py >output.log 2>&1

The same applies to pythonw.exe too.

--
Gabriel Genellina

peter

2/19/2008 8:24:00 AM

0


> import sys
> sys.stdout = open("stdout.log","w")
> sys.stderr = open("stderr.log","w")
> print "This goes to stdout"
> print >>sys.stderr, "This goes to stderr"
>

This did the trick. Thanks

Peter