Re: Questions about Expect buffers & operation
- From: Bruce Hartweg <bruce-news@xxxxxxxxxx>
- Date: Mon, 26 Jun 2006 20:13:07 -0500
Dave Harper wrote:
After having used expect for a number of years I am now working on a script
which has caused me more problems than I've had in a long time. The target
interface consists of a telnet session to a computer which contains a number
of "virtual consoles". By sending a "^A" character to the channel, the
computer will switch to the next virtual channel. The console manager within
the computer contains separate buffers for each virtual console, so sending a
^A character can often produce a large amount of return data, depending on
what was going on with that particular console. I find I am now dealing with
the operation of Expect at a deeper level than I have before and this has led
to some questions that I have been unable to answer from reading the book.
1) There are two buffers of interest to me. The first is the kernel buffer
which buffers up data until it is read by the channel (in my case this is
actually several buffers managed by the console manager). The second
buffer is the internal buffer within Expect which is the one that a pattern
is matched against. When does Expect read data from the kernel buffer into
the internal buffer? Whenever data is available on the channel or only
when an expect command within the script is executed?
it reads from the external buffer only when it needs to to make a match
it the internal buffer matches your expression no external read is done
2) When a timeout occurs, data in the internal buffer is not moved to the
expect_out(buffer). If I need to flush the internal buffer, I should do an
"expect *", according to comments on page 96 of the book. However, a
subsequent timeout on another expect could then leave me in a situation
where the expect_out(buffer) still contains data from the "expect *". Is
it legimate to do something like: set expect_out(buffer) "" ?
yes, it is perfectly legal for you to clear out elements of the expect_out array
3) Along the lines of question #1, if I do "expect *", the internal buffer is
flushed. Will this also read and flush the kernel buffer if data is
available?
nope. because * will match whatever the internal buffer holds (including nothing)
so even if there is a bunch of stuff int he external buffer - it doesn't get read
to clear both buffer, you first need to try and match something you know won't
match, then expect will keep reading the external buffer trying to match it until
everything is read, then the expect will timeout (which you already know does NOT
transfer anything in to the expect_out array and keeps all the stuff in the internal
buffer to be available for the next match attempts) then follow it witht the expect *
to clear the internal buffer.
Bruce
.
- Follow-Ups:
- Re: Questions about Expect buffers & operation
- From: Dave Harper
- Re: Questions about Expect buffers & operation
- References:
- Questions about Expect buffers & operation
- From: Dave Harper
- Questions about Expect buffers & operation
- Prev by Date: Re: Regex Help
- Next by Date: Re: Vim script for Tcl; request for input.
- Previous by thread: Questions about Expect buffers & operation
- Next by thread: Re: Questions about Expect buffers & operation
- Index(es):
Relevant Pages
|
|