Simple Expect problem

Discussion in 'Perl Misc' started by bpatton, Mar 22, 2007.

  1. bpatton

    bpatton Guest

    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 -
     
    bpatton, Mar 22, 2007
    #1
    1. Advertising

  2. bpatton

    Mumia W. Guest

    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/clpmisc/clpmisc_guidelines.html
     
    Mumia W., Mar 22, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kai-Uwe Bux
    Replies:
    1
    Views:
    1,176
    Kai-Uwe Bux
    Dec 21, 2008
  2. Simon Strandgaard

    how to expect eof with expect+pty

    Simon Strandgaard, Dec 20, 2006, in forum: Ruby
    Replies:
    4
    Views:
    390
    Simon Strandgaard
    Dec 20, 2006
  3. erik
    Replies:
    7
    Views:
    734
  4. Expect::Simple

    , Dec 1, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    90
  5. Phil
    Replies:
    0
    Views:
    181
Loading...

Share This Page