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

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.

Replies are listed 'Best First'.
Re^5: Checking for STDIN
by AltBlue (Chaplain) on Jul 30, 2008 at 02:16 UTC
    You seem to confuse the meaning of STDIN. In "filter" mode, STDIN won't be the terminal, e.g. echo 'foo' | ./test.pl
      I am sorry but the method you specified does not work for what i am trying to do in cron.

      Please refer to: http://www.unix.com.ua/orelly/perl/cookbook/ch15_03.htm

      The -t operator tells whether the filehandle or file is a tty device. Such devices are signs of interactive use. This only tells you whether your program has been redirected. Running your program from the shell and redirecting STDIN and STDOUT makes the -t version of I_am_interactive return false. Called from cron, I_am_interactive also returns false.

      The POSIX test tells you whether your program has exclusive control over its tty. A program whose input and output has been redirected still can control its tty if it wants to, so the POSIX version of I_am_interactive returns true. A program run from cron has no tty, so I_am_interactive returns false.