Can't redirect output

Chris Gonnerman chris.gonnerman at usa.net
Fri Feb 23 08:44:39 EST 2001


From: "Robert Olney" <rolney at pcug.org.au>
Subject: Can't redirect output
> I am running Python 2.0 on Windows 98. When I try to redirect output
> from a command prompt, e.g.
> 
> C:\> python hello.py > out.txt
> 
> the output is printed on the screen and not to the file. Why? 

Is the output you are talking about from print commands and/or 
sys.stdout.write(...) calls, or is it error messages?  Unix and Windows 
processes have two standard channels for writing messages, stdout and
stderr, which Python maps to sys.stdout and sys.stderr.  The redirection
you show only redirects stdout/sys.stdout.

On Unix (and reportedly Windows NT) you can write:

    python hello.py >out.txt 2>errors.txt

which separates the output channels, or

    python hello.py >out.txt 2>&1

to combine them in the file.  Unfortunately this does not work on Win9X,
but there is a program available called stderr which combines the two 
channels.  Get it from:

    http://www.teaser.fr/~amajorel/stderr/

IF NONE OF THIS HELPS YOU... please post your hello.py so we can
inspect it.

>The FAQ
> mentions that this is a problem under Linux.

I'll have to look at the FAQ, I'm not sure why Linux would have a problem 
with it.






More information about the Python-list mailing list