Simple Expect problem

B

bpatton

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 {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 <y/n> ',
sub {my $fh = shift;
$fh->send('y');
exp_continue;
}
],
);

- Hide quoted text -
- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top