in reply to Altering Behavior of a Script

Hi ikegami,

I was playing with the -t STDIN that you mentioned but I think I missed something. Please see below.

Here's the ask_input.pl
#!/usr/bin/perl print "Enter your answer?\n"; if ( -t STDIN ) { <STDIN>; print "Terminal was used.\n"; } else { print "Not a terminal.\n"; } print "Done.\n";
Here's the caller.pl
#!/usr/bin/perl use strict; system( "perl /tmp/ask_input.pl" );
So, when I run caller.pl on the terminal, it will still ask for the input... but I thought it should not do this.

Replies are listed 'Best First'.
Re^2: Altering Behavior of a Script
by ikegami (Patriarch) on Sep 03, 2009 at 20:43 UTC

    system doesn't mess with any of the file handles passed to the child. If caller.pl is called interactively, so is ask_input.pl.

    But why are you using -t? You need to get your answer from somewhere. You can't test if you're going to receive an answer from a terminal, so that's the last place you should check. You should base whether you prompt or not based on the presence or absence of the answer elsewhere (e.g. argument, config file).

      Ah, I see what you mean.