How can I tell if STDIN is connected to a terminal in Perl?
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.
You might also be interested in IO::Interactive to figure out if Perl thinks it is interacting with a user. Simply being connected to a tty doesn't mean the user is going to see what you do.
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