Find whether a Julia script has the output redirected to the screen or a pipe?

How do I find whether a Julia script running in the terminal has the output (stdout) redirected to the screen or a pipe?

$ ./julia_script  # outputs to the terminal
$ ./julia_script  | command  # pipes the output

The type of stdout should help you determine that:

$ julia -e 'println(typeof(stdout))'
Base.TTY

$ julia -e 'println(typeof(stdout))' | cat
Base.PipeEndpoint
3 Likes

Wow. Excellent!
Thank you!