f



expect script : "expect 'X', send 'Y'" until expect "Z".

Hi.


I am having some difficulties with an expect script, and was hoping
someone could help me out here.


I am running a scripted telnet session to some 'black box' appliance,
and would like to retrieve the output of a particular command.
However, the output of the command is longer than a single screen
full. Since it was designed for interactive use, you get the magic
string "[=More (xx%)=]" after each screenfull of output, at which
point the command expects you to hit the spacebar in order to get
another screenfull of output.

Of course, I could just "send <space>" a few times, but since I have
no idea how long the output will be in advance, this does not appear
to be such a good approach. It looks like I would have to do something
were I keep sending a space as long as I keep getting/expecting the
string "[=More (xx%)=]", and stop doing that after I have
gotten/expected the prompt again. (which is "% ").

Does anyone have any idea on how to do such a thing in expect ? Of
course, other suggestions to tackle the same problem are welcome as
well of course.



Sincerely,

John Smith.
0
lbalbalba (26)
10/20/2004 11:05:52 AM
comp.lang.tcl 23428 articles. 2 followers. Post Follow

3 Replies
1117 Views

Similar Articles

[PageSpeed] 22

"J.Smith" <lbalbalba@hotmail.com> wrote in message
news:737da4e2.0410200305.1f12696f@posting.google.com...
> Hi.
>
>
> I am having some difficulties with an expect script, and was hoping
> someone could help me out here.
>
>
> I am running a scripted telnet session to some 'black box' appliance,
> and would like to retrieve the output of a particular command.
> However, the output of the command is longer than a single screen
> full. Since it was designed for interactive use, you get the magic
> string "[=More (xx%)=]" after each screenfull of output, at which
> point the command expects you to hit the spacebar in order to get
> another screenfull of output.
>
> Of course, I could just "send <space>" a few times, but since I have
> no idea how long the output will be in advance, this does not appear
> to be such a good approach. It looks like I would have to do something
> were I keep sending a space as long as I keep getting/expecting the
> string "[=More (xx%)=]", and stop doing that after I have
> gotten/expected the prompt again. (which is "% ").
>
> Does anyone have any idea on how to do such a thing in expect ? Of
> course, other suggestions to tackle the same problem are welcome as
> well of course.
>
>
>
> Sincerely,
>
> John Smith.

I've not done *any* work with expect, but I do plan on it, so I read
postings about it all the time.  From what I have seen in some sample
programs, you can give expect multiple  match strings, so why not just:

set expectingmore 1
set moreprompt "=]"
set endprompt "% "

while (expectingmore) {
expect {
timeout {set expectingmore 0}
"$moreprompt" {send " "}
"$endprompt" {set expectingmore 0}
}
}

or, perhaps more simply:

while (1) {
expect {
timeout break
"=]" {send " "}
"% " break
}
}

tcl/expect veterans, please proofread!

Rufus


0
nospam21 (19047)
10/20/2004 2:44:42 PM
In article <1098283492.TP2TllaGGNeryKYOiJbYJQ@teranews>,
Rufus V. Smith <nospam@nospam.com> wrote:
>
>"J.Smith" <lbalbalba@hotmail.com> wrote in message
>news:737da4e2.0410200305.1f12696f@posting.google.com...
>> Hi.
>>
>>
>> I am having some difficulties with an expect script, and was hoping
>> someone could help me out here.
>>
>>
>> I am running a scripted telnet session to some 'black box' appliance,
>> and would like to retrieve the output of a particular command.
>> However, the output of the command is longer than a single screen
>> full. Since it was designed for interactive use, you get the magic
>> string "[=More (xx%)=]" after each screenfull of output, at which
>> point the command expects you to hit the spacebar in order to get
>> another screenfull of output.
>>
>> Of course, I could just "send <space>" a few times, but since I have
>> no idea how long the output will be in advance, this does not appear
>> to be such a good approach. It looks like I would have to do something
>> were I keep sending a space as long as I keep getting/expecting the
>> string "[=More (xx%)=]", and stop doing that after I have
>> gotten/expected the prompt again. (which is "% ").
>>
>> Does anyone have any idea on how to do such a thing in expect ? Of
>> course, other suggestions to tackle the same problem are welcome as
>> well of course.
>>
>>
>>
>> Sincerely,
>>
>> John Smith.
>
>I've not done *any* work with expect, but I do plan on it, so I read
>postings about it all the time.  From what I have seen in some sample
>programs, you can give expect multiple  match strings, so why not just:
>
>set expectingmore 1
>set moreprompt "=]"
>set endprompt "% "
>
>while (expectingmore) {
>expect {
>timeout {set expectingmore 0}
>"$moreprompt" {send " "}
>"$endprompt" {set expectingmore 0}
>}
>}
>
>or, perhaps more simply:
>
>while (1) {
>expect {
>timeout break
>"=]" {send " "}
>"% " break
>}
>}
>
>tcl/expect veterans, please proofread!
>
>Rufus
>
>

Nice work!  For not having worked with Expect, you sure fake it well.

A few aesthetic refinements on your suggestions are possible.  In
particular, "while 1 ..." in Expect code should make one consider 
whether a better solution will involve exp_continue.  <URL:
http://groups.google.com/groups?th=a3a4d69833cd0bed > explains more.
0
claird (2363)
10/20/2004 4:08:04 PM
"Rufus V. Smith" <nospam@nospam.com> wrote in message 
news:1098283492.TP2TllaGGNeryKYOiJbYJQ@teranews...
>
> while (1) {
> expect {
> timeout break
> "=]" {send " "}
> "% " break
> }
> }
>

Yup, that works as advertised. Thanks.


Sincerely,

John Smith. 


0
lbalbalba (26)
10/23/2004 8:15:27 AM
Reply: