I should clarify, I am not looking for a timeout, as the program halts until an actual user enters something into the command window during execution. I am looking for the script to issue what a physical person needs to do when it prompts with the screen
"Do you want to read the file? 1 for yes, 2 for no. (Default is 2)"
in this case, if someone was physically at the computer during execution and they wanted to read the file, they would type "1" and hit enter. That is what I am looking to have my script do automatically. I looked into expect, and their are two primary issues with it unfortunately.
One is it appears to depend on using files and I am not using any files, perhaps I am incorrect on this?
Two, I am developing this for a company where I can't put this on our systems without waiting past a time where the deadline for the larger piece of code that this script is associated with.
Edit: I have decided to retrieve Expect for my local system at least and begin the process of making point two of this post moot. Hopefully Expect will be able accomplish what I need.
| [reply] [d/l] |
I'm not sure why you can't use Expect, but the other alternative is to use IPC, read perldoc perlipcHere is a super simple example using the bc calculator, but you would run your script. This uses IPC::Open2 which comes standard in Perl. Just plugin your script, and answer the prompts in order as you receive them.
#!/usr/bin/perl
#prompts for an string to evalute
#(line 2+2, or 5x7, 5*6 / 3 , etc)
#sends it to the bc calculator,
#then reads the answer, and prints.
use IPC::Open2;
use strict;
use warnings;
my ($rd, $wr);
open2($rd, $wr, "bc");
print "Enter a string to evaluate\n";
my $prompt= <STDIN>;
print $wr "$prompt";
my $x = <$rd>;
print $x;
print "Enter another string to evaluate\n";
my $prompt= <STDIN>;
print $wr "$prompt";
my $x = <$rd>;
print $x;
close($rd);
close($wr);
| [reply] [d/l] |
| [reply] |