Re: Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- From: Andry <yandry77@xxxxxxxxx>
- Date: Fri, 19 Sep 2008 02:01:29 -0700 (PDT)
On Sep 19, 10:25 am, Andry <yandr...@xxxxxxxxx> wrote:
On Sep 19, 8:43 am, Phani Ranjan <PhaniRan...@xxxxxxxxx> wrote:
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
Hi Phani,
Thanks but I had already tried that.
I doesn't work in my case.
I think it's all about the interaction with Expect functions...
(expect, send and so on...) but I don't know how to get this work.
I tried google-ing a lot and searching other group discussions for
similar issues but with no success.
Any idea?
Ciao,
Andrea
Just another comment.
It seems the same problem is present with "print" commands.
Does that ring any bell to anyone?
Thanks,
Andrea
.
- Follow-Ups:
- References:
- Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- From: Andry
- Re: Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- From: Phani Ranjan
- Re: Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- From: Andry
- Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- Prev by Date: Re: Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- Next by Date: Re: Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after)
- Previous by thread: Re: 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
|