Where goes stdout ?

Fredrik Lundh fredrik at pythonware.com
Sun Feb 11 16:28:41 EST 2001


Siggy Brentrup wrote:>
> > How to check in a script if stdout is a console (or xterm) or if it is
> > redirected to something else (file, pipe...) from command line.
>
> import os, sys
>
> if os.isatty(sys.stdout.fileno()):
>     # output goes to a tty

or:

    if sys.stdout.isatty():
        # output goes to a tty

Cheers /F





More information about the Python-list mailing list