match_max

While reading output, more than 2000 (think of a 25 x 80 terminal) bytes can force earlier bytes to be "forgotten". This may be changed with the function match_max. (Note that excessively large values can slow down the pattern matcher.) If patlist is full_buffer, the corre- sponding body is executed if match_max bytes have been received and no other patterns have matched. Whether or not the full_buffer keyword is used, the forgotten characters are written to expect_out(buffer).

             taken from 'man expect'

I've found that match_max can cause expect_out(buffer) to become undefined. Redefine it after calling match_max to get round this.

   match_max 5000
   set expect_out(buffer) {}

As noted by Cameron Laird here: http://phaseit.net/claird/comp.lang.tcl/expect.html