Skip to Content
Exploring Expect
book

Exploring Expect

by Don Libes
December 1994
Intermediate to advanced
606 pages
16h 7m
English
O'Reilly Media, Inc.
Content preview from Exploring Expect

The full_buffer Keyword

On page 146, I described how expect discards input when its internal buffer is exceeded. The special pattern full_buffer matches when no other patterns match and expect would otherwise throw away part of the input to make room for more.[29] When full_buffer matches, all of the unmatched input is moved to expect_out(buffer).

As with other special patterns, such as eof and timeout, full_buffer is only recognized when none of the -gl, -re, or -ex flags has been used.

The following fragment was written for someone who needed a program that would “spool up” a relatively slow stream from the standard input and send it to a telnet process every 3 seconds. They wanted to feed telnet with a few big chunks of data rather than lots of tiny ones because they were running on a slow network that could not afford the overhead.

set timeout 3
while 1 {
      expect_user {
        eof exit
        timeout {
            expect_user "*"
            send $expect_out(buffer)
        }
        full_buffer {send $expect_out(buffer)}

}

The program works by sitting in a loop which waits for three seconds or a full buffer, whichever comes first. If the buffer fills, it is sent out immediately. If three seconds pass, another expect command is executed to retrieve whatever data has arrived, and that data is sent to the remote side.

The expect_user command is a special version of the expect command that reads from the standard input. I will describe this command in detail in Chapter 8 (p. 188).

[29] There is a wayto obtain the discarded input without ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

AI Agents in Action

AI Agents in Action

Micheal Lanham
Learning Go

Learning Go

Jon Bodner

Publisher Resources

ISBN: 9781565920903Supplemental ContentErrata Page