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.
...
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
}