redirect to > and to console ?

Steve Holden sholden at holdenweb.com
Fri Jul 26 10:13:49 EDT 2002


"Tim Hammerquist" <tim at vegeta.ath.cx> wrote in message
news:slrnak298k.e04.tim at vegeta.ath.cx...
> Gerhard Haering graced us by uttering:
> > "Shagshag13" wrote:
> >> i use many python script like that :
> >> ./myscript.py file_in > file_out
> >>
> >> i wish i would sometimes like to force output to be redirect to
> >> console instead of file file_out, is there any way of doing that?
> >> (for example to display errors message while file_in will contain
> >> only data processed) [...]
> >
> > Unix and Windows consoles have two different output streams: the
> > standard output one and the error stream.
> >
> > Standard output is accessible from Python as sys.stdout, the error
> > stream as sys.stderr.
> >
> > To write to the error stream, either one of
> >
> >     sys.stderr.write("foobar\n")
> >
> > and
> >
> >     print>> sys.stderr, "foobar"
>
> One thing that concerns me is how well do the COMMAND.COM/CMD.EXE shells
> handle redirection?  I know that DOS used to support the standard '>'
> redirection, but I don't remember any robust way of handling stderr on
> the command line.
>
> Various *nix (and cygwin, yes) shells can use:
>
>   $ command > file_out 2> file_err
>
>   $ command > file_both 2>&1
>
>   $ command &> file_both
>
> ...and I think I heard CMD.EXE had slightly better support, but how does
> Win32's native command line stream redirection really compare?
>


While I can't be definitive about htis (maybe Mark Hammond *could*), one
thing it's always worth remebering is that certain Windoze command
interpreters will fail to handle

    prog.py > output.txt

when they *will* cirrectly handle

    python prog.py > output.txt

I seem to remember this particular form of brain-death belongs to Windows NT
4.0 (why was there never an NT 4.anything else, I wonder), since "lesser"
operating systems didn't even have the ability to associate the ".py"
extension with the Ptyhon interpreter.

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list