I have a small Python utility which should be run only as a pipe. I want it to print out the help message when it runs stand alone. How can a process know whether it is being used as a pipe. Comparing sys.stdin
and sys.__stdin__
does not work.
You can use isatty
:
if sys.stdin.isatty():
It will be True
if standard input is a tty, which roughly means it's being used directly, outside a pipe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With