Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Simple Expect problem

Reply
Thread Tools

Simple Expect problem

 
 
bpatton
Guest
Posts: n/a
 
      03-22-2007
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 -

 
Reply With Quote
 
 
 
 
Mumia W.
Guest
Posts: n/a
 
      03-22-2007
On 03/22/2007 08:58 AM, bpatton wrote:
> 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
> [ snipped scripts without any explanation of what is wrong with them ]


Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clp...uidelines.html


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: hashtable or map? (map inserts not behaving as I expect - and I cant find a decent simple example for hashtable) Kai-Uwe Bux C++ 1 12-21-2008 09:25 PM
Simple C# ASP.NET problem (i expect) ChipM Software 0 05-30-2007 02:59 PM
how to expect eof with expect+pty Simon Strandgaard Ruby 4 12-20-2006 04:00 PM
Bug in $obj->expect() ... ? (Expect 1.15) Phil Perl Misc 0 07-07-2006 07:25 AM
Expect::Simple sunadmn@gmail.com Perl Misc 0 12-01-2005 10:11 PM



Advertisments