I’ve noticed that curl can tell whether or not I’m redirecting its output (in which case it puts up a progress bar).
Is there a reasonable way to do this in a Python script? So:
$ python my_script.py
Not redirected
and
$ python my_script.py > output.txt
Redirected!
Actually, what you want to do here is find out if
stdinandstdoutare the same thing.The longer but more traditional version of the are they the same file test just compares
st_inoandst_dev. Typically, on windows these are faked up with a hash of something so that this exact design pattern will work.