Simple expect problem .

Simple expect problem .

am 21.03.2007 19:31:56 von Billy Patton

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? ";
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 {exp_continue;}
],
['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 {exp_continue;}
],
['Are you ready to quit ',
sub {my $fh = shift;
$fh->send('y');
exp_continue;
}
],
);
}