Where goes stdout ?

Siggy Brentrup bsb at winnegan.de
Sun Feb 11 15:51:36 EST 2001


"Gillou" <glenfant at equod.com.nospam> writes:

> Hi,
> 
> 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
    pass
else:
    # output is redirected
    pass

HTH
  Siggy





More information about the Python-list mailing list