title: How do I check if a Perl script is running in a terminal?
body: <p>I'm trying to determine, within a Perl script on Linux, whether it's running in a terminal.</p>
  
  <p>That is, I need code that:</p>
  
  <ul>
  <li>returns true when simply running on the command-line</li>
  <li>also returns true when running <code>./myscript.pl | less</code> or even <code>./myscript.pl &lt;/dev/null &gt;/dev/null 2&gt;/dev/null</code></li>
  <li>returns false when running in a cron job, or as a CGI script</li>
  </ul>
  
  <p>Especially because of the second bullet, I can't use <code>-t STDOUT</code> and variations, and also <a href="http://search.cpan.org/~bdfoy/IO-Interactive-0.0.6/lib/IO/Interactive.pm" rel="noreferrer">IO::Interactive</a> is of no use.</p>
  
  <p>The information does appear to be available.  If I run <code>ps</code>, it shows an entry like <code>pts/2</code> in the <code>TTY</code> column, even when I run <code>./myscript.pl &lt;/dev/null &gt;/dev/null 2&gt;/dev/null</code>, and <code>?</code> when running as a cron job or CGI script.</p>
  
  <p>Is there an elegant way to determine this in a Perl script?  I'd rather not have to parse the output of <code>ps</code>.</p>