expect: how to clear expect_out(1,string)
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

expect: how to clear expect_out(1,string)

From: <andyhaupt@netscape.net>
Date: Mon Mar 06 2006 - 18:26:58 CET

Hello,

I'm using the following pattern in an expect script

expect -re "(pat1)?(pat2)"

ie. pat1 can match 0 or 1 time, pat2 needs to match always.

the output is stored in expect_out(1,string) and expect_out(2,string)
but in the case that pat1 does not match expect_out(1,string) is still
filled with the output of the last successful match.
This might sound strange but is also documented in 'Exploring Expect'
on page 112 in my copy.

Now if I base a decision on the value of expect_out(1,string) I might
be mislead since it does not refer to the current match so I'd rather
have an empty string.
Is there a way to clear expect(1,string)?
What is the best way to base decisions on whether pat1 has been seen?

I was thinking about a hierarchical approach like this
expect {
   -re "(pat1)(pat2)" { # pat1 and pat2 have been seen }
   -re "(pat2)" { # only pat2 has been seen }
}
is this really the way to do it?

rgds
andreas
Received on Sun Apr 30 02:25:00 2006