Re: Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- From: Phani Ranjan <PhaniRanjan@xxxxxxxxx>
- Date: Thu, 18 Sep 2008 23:43:19 -0700 (PDT)
On Sep 18, 1:58 pm, Andry <yandr...@xxxxxxxxx> wrote:
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
Hi Andrea..
please go through the below.. example..
print "countdown!\n\n";
$|=1;
#$|=0;
for ($i=10;$i>0;$i--) {
print "$i \r";
sleep 1;
}
$|=0;
print "Blast off!\n"
there is a varible $| which can be enabled or disabled, if enabled
forces output after every write or print.. other wise waits till the
buffer gets filled..
"$| If set to nonzero, forces a flush after every write or print When
you want your pipes to be piping hot "
hope this should solve your problem
Cheers
Phani
.
- Follow-Ups:
- References:
- Prev by Date: Re: How to avoid multiple Inclusions of perl modules.. or how to detect mutliple inclusions.
- Next by Date: Re: Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- Previous by thread: Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- Next by thread: Re: Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- Index(es):
Relevant Pages
|