gg48gg has asked for the wisdom of the Perl Monks concerning the following question:
Hi all
I am having trouble with the below code. Instead of waiting for the prompt which looks something like '1>', each of the lines in the file is being sent without waiting for the prompt. If I take it out of the foreach loop, and explicitly
$exp->send
$exp->expect
for each line, then it works fine. But, I need to get it to send each line of the file, wait for the prompt, send the next line, rinse, repeat.
It seems that perl is not waiting for the $exp->expect to be true before looping to next. How can I fix this? Thanks.
#now send each line of the $isqlcommandfile to isql foreach my $line (<ISQLCOMMANDFILE>) { #usleep(4000); chomp $line; $exp->send("$line\n"); $exp->expect(2000, '-re', '\d+\> ') if (! $line=~m/^\s*exit\s*$/i); } $exp->soft_close();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problems using Expect.pm in foreach loop
by keszler (Priest) on Sep 10, 2011 at 05:40 UTC | |
by duyet (Friar) on Sep 10, 2011 at 06:12 UTC | |
by gg48gg (Sexton) on Sep 11, 2011 at 00:11 UTC | |
by keszler (Priest) on Sep 11, 2011 at 04:59 UTC | |
by gg48gg (Sexton) on Sep 22, 2011 at 04:11 UTC | |
by gg48gg (Sexton) on Oct 04, 2011 at 21:06 UTC |