I am trying to learn how to use Expect in my perl scripts and I am doing a very poor job of it so far. I am hoping I can get some help from the monks. I have written two very basic programs just to see if I can figure out how this works and I guess I am just not getting it.
Here is the first program
Expect_Test
use strict;
use Expect;
my $expect = Expect->spawn("/usr/foo/namer") or die "$!\n";
print $expect "PrimeLord\n";
my $result = $expect->expect(15,"name:") or die "Didn't get what I was
+ looking for:\n";
Like I said a very simple script that just calls another script
namer. Here are the contents of the namer script.
use strict;
use Expect;
print "What is your name: ";
chomp (my $name = <STDIN>);
if ($name =~ /primelord/i) {
print "Hello PrimeLord!\n";
} else {
print "Hello $name! I don't know you!\n";
}
So I would expect when I run Expect_Test for it to spawn namer and pass it PrimeLord when it sees What is your name. However what happens is namer is called. I see PrimeLord printed to STDOUT. Then I see What is your name: printed to the screen and then the program just exits. I thought maybe I was printing the answer to my expect too soon, but even when I move it after the expect line it didn't work. This seems like it should be very simple, but I just can't get it. Any help would be very appreciated. Thanks!
-Prime
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.