Error messages when using the Console Module
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Feb 15 19:56:20 EST 2008
En Fri, 15 Feb 2008 11:59:07 -0200, peter <peter.mosley at 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
More information about the Python-list
mailing list