Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- From: Andry <yandry77@xxxxxxxxx>
- Date: Thu, 18 Sep 2008 01:58:05 -0700 (PDT)
Hi all,
I have a timing issue with the usage of "sleep" within my perl-expect
script.
This is an example script to describe my problem:
**********************************************************************************************************
#!/usr/bin/perl -w
use Expect;
$timeout = 5;
$exp = new Expect();
$exp->raw_pty(1);
$exp->spawn("ssh -l username 10.17.39.29");
$exp->expect($timeout, [ "[Pp]assword" => sub { $_[0]->send("password
\n"); } ]);
$exp->expect($timeout, [ "prompt-string" => sub { $_[0]->send("ls -l
\n"); } ]);
sleep 2;
$exp->expect($timeout, [ "prompt-string" => sub { $_[0]->send("ls
\n"); } ]);
sleep 5;
$exp->interact();
*********************************************************************************************************
What happens is that the sleep commands are not executed right after
the preceding "$exp->..." command in the code, but they are executed
BEFORE that.
For instance, the output of this script should give:
1) ssh session...
2) login (password)...
3) execute "ls -l"
4) sleeping 2 seconds
5) execute "ls"
6) sleeping 5 seconds
Instead the actual result is:
1) ssh session...
2) login (password)...
3) sleeping 2 seconds!!!
4) execute "ls -l"
5) sleeping 5 seconds!!!
6) execute "ls"
Btw, if use simple "send" commands, without "expect" constructions, to
execute the "ls -l" and "ls" commands in a sequence, then the "sleep"
commands are executed before any "send" command...
Can you help with this? How can I get "sleep" to execute at the
desired time (simply following the order of the instructions in the
code)?
Thank you,
Andrea
.
- Follow-Ups:
- Prev by Date: Re: How to avoid multiple Inclusions of perl modules.. or how to detect mutliple inclusions.
- Next by Date: Re: How to avoid multiple Inclusions of perl modules.. or how to detect mutliple inclusions.
- Previous by thread: How to avoid multiple Inclusions of perl modules.. or how to detect mutliple inclusions.
- Next by thread: Re: Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- Index(es):
Relevant Pages
|