in reply to Re^2: automatically giving user input to a command line
in thread automatically giving user input to a command line
Here 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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: automatically giving user input to a command line
by tfredett (Sexton) on Jun 13, 2012 at 20:50 UTC |