Use isatty to determine if standard output is piped at runtime --Qiita
I tried to do this with Python, so I made a note.
isatty.py
import sys
print(sys.stdout.isatty())
When executed, it becomes like this
$ python isatty.py
True
$ python isatty.py | cat
False
This looks good
isatty.py
import os, sys
print(os.isatty(sys.stdout.fileno()))
Recommended Posts