R – How to tell if STDIN is connected to a terminal in Perl

perlstdinterminal

How can I tell if STDIN is connected to a terminal in Perl?

Best Answer

if (-t *STDIN) {
  # stdin is connected
} else {
  # stdin is not connected
}

I usually use this in conjunction with -t *STDOUT, to find out if I'm running from an interactive shell, or from cron, to enable more output.