Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Updating a variable value on a pattern matching -re in Expect

2 views
Skip to first unread message

2Re...@gmail.com

unread,
Apr 4, 2008, 3:57:01 PM4/4/08
to
Hi,

I was wondering if anyone knows of a way to update the contents of a
variable within an expect string so that it could be reused with
different values on multiple passes processed via the exp_continue
statement. I have written a utility that reads terminal streams for
screen coordinates on a standard 24x80 definition. I treat lines
20-23 with the same code while I use line 24 as my trigger to signal
that I am finished with my parsing. My debugging of this problem
indicates that Expect binds the value of any variable once on the
initial pass through it's evaluation and I would like to be able to
have it freshly look at the value through each iteration. Here is a
sample of what I am looking to be able to accomplish:

...
set counter 20
send "key
text"
expect {
timeout {handle
timeout condition}
-re "\\\[24;\\d{1,2}H" {handle
end of screen condition}
-re "\\\[$counter;\\d{1,2}H" {process
these 3 similar lines 20-23

send some text

incr counter

exp_continue}
}

When I run this with debugging turned on, I run into a timeout
condition on the second iteration through the code. Even though my
counter variable has been incremented to 21, Expect is still looking
for a match on 20 and doesn't find it in the terminal stream.

I am hoping that someone can help me figure out how to get Expect to
recognize that the $counter variable has changed and that it needs to
re-evaluate that pattern matching condition.

Thanks in advance for your assistance.

Cameron Laird

unread,
Apr 6, 2008, 11:23:38 AM4/6/08
to
In article <df53eb70-7155-4eb2...@b1g2000hsg.googlegroups.com>,
.
.
.
While I have trouble understanding the description, I'm
fairly sure the [expect]-[exp_continue] pair simply lacks
the semantics you're after. You can unwrap the
[exp_continue], though, and code something like

...
set counter 20
send "key text"

while 1 {


expect {
timeout {
handle timeout condition
}

-re "\\\[$counter;\\d{1,2}H" {
if {24 == $counter} {


handle end of screen condition

} else {


process these 3 similar lines 20-23
}
}
}

send $some_text
incr counter
}

0 new messages