Search code examples
perlterminalstdin

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


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


Solution

  • 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.