Re: Questions about Expect buffers & operation



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
.



Relevant Pages

  • Questions about Expect buffers & operation
    ... After having used expect for a number of years I am now working on a script ... The first is the kernel buffer ... actually several buffers managed by the console manager). ... buffer is the internal buffer within Expect which is the one that a pattern ...
    (comp.lang.tcl)
  • Re: Questions about Expect buffers & operation
    ... possible and then expect something like ".+" until a timeout ... doing things like sending characters to each virtual console that otherwise ... The first is the kernel buffer ... buffer is the internal buffer within Expect which is the one that a pattern ...
    (comp.lang.tcl)
  • Re: C# Socket Programming
    ... i am a software developer and i need to use .NET 2.0 with C#. ... So i have init a UDP socket like socket with the ... SocketException that say the internal Buffer size is either to small ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Questions about Expect buffers & operation
    ... always done as you suggest to flush a channel - set as short timeout as ... To try and speed things up I've tried doing things like sending characters to each virtual console that otherwise would not appear in the data stream and then doing an expect on those characters, or just doing a straight Tcl read on the channel followed by an "expect *" but none of these approaches have been bullet-proof. ... The first is the kernel buffer ... buffer is the internal buffer within Expect which is the one that a pattern ...
    (comp.lang.tcl)
  • Re: Expect regular expression matching
    ... > I find it difficult to match the regular expression in the Expect ... Matching is done against what is stored in this internal buffer. ... When you match a pattern in this internal buffer, all characters ...
    (comp.lang.tcl)