|
Posted by bpatton on March 21, 2007, 2:31 pm
Please log in for more thread options
I'm trying to write a wrapper(X) that calls another wrapper(Y).
Y prompts the user for information using STDOUT.
My job is for regression testing, so I must wiggle all the prompts for
all values.
Here is a very simple example of what I want to do. y.pl
#!/usr/local/bin/perl
use strict;
use warnings;
$| = 1;
print "Begin command line IO now.\n";
NUMBER:
print "Enter number : ";
my $number = <>;
print("Letters entered!\n") , goto(NUMBER) if $number =~ /[a-zA-Z]/;
print "Number entered : $number\n";
LETTERS:
print "Enter alpha characters : ";
my $name = <>;
print("Numbers entered!\n") , goto(LETTERS) if $name =~ /[0-9]/;
print "Letters entered : $name\n";
print "Are you ready to quit? <y/n> ";
my $q = <>;
goto NUMBER if $q =~ /n/;
exit 1571234; # make sure it gets strange error code
#################################################################################
Here is what I'm trying to do with Expect x.pl :
#!/usr/local/bin/perl
use strict;
use warnings;
use FileHandle;
use Expect;
$| = 1;
my $exp = new Expect;
$exp->raw_pty(1);
$exp->spawn("y.pl");
while (1) {
my $get = $exp->expect(1,
['Begin command line IO now.',
sub
],
['Enter number.*',
sub {my $fh = shift;
$fh->send('1');
exp_continue;
}
],
['Numbers entered!.*',
sub { exp_continue;}
],
['Enter alpha characters : ',
sub {my $fh = shift;
$fh->send('a');
exp_continue;
}
],
['Letters entered.*',
sub
],
['Are you ready to quit <y/n> ',
sub {my $fh = shift;
$fh->send('y');
exp_continue;
}
],
);
}
|
| Similar Threads | Posted | | Problem with very simple Expect script | April 24, 2005, 8:42 pm |
| Expect::Simple | December 1, 2005, 4:19 pm |
| Expect::Simple | December 2, 2005, 9:22 am |
| Expect.pm module help - simple question... | March 15, 2005, 12:27 pm |
| XML::Simple Problem | February 16, 2006, 5:13 pm |
| DBI does not do what I expect... | March 12, 2008, 4:18 am |
| using Net::SSH::Perl with Expect | November 21, 2005, 3:41 pm |
| Expect: Getting PID at both ends of ssh | January 22, 2007, 3:08 pm |
| Expect and xterm | February 27, 2007, 11:12 pm |
| Perl Expect question | November 8, 2004, 12:20 pm |
|