in reply to Re: Checking for STDIN
in thread Checking for STDIN

-t will not work because I am using my script in a cron job sometimes.

Replies are listed 'Best First'.
Re^3: Checking for STDIN
by AltBlue (Chaplain) on Jul 30, 2008 at 02:03 UTC

    What do you mean?!

    Save this code to a file and test it.

    #!/usr/bin/perl -wl use strict; open my $fh, '>', '/tmp/test.log' or die $!; print $fh 'STDIN ', ( -t STDIN ? 'IS' : 'is NOT' ), ' available' or di +e $!; close $fh or die $!;
      In a cron job -t would evaluate to false which in my case would mean my script would think info is being piped to it when I have a commandline option -logfile <file> being used to specify input.
        You seem to confuse the meaning of STDIN. In "filter" mode, STDIN won't be the terminal, e.g. echo 'foo' | ./test.pl