Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

expect: full_buffer and expect_out(buffer)

1,622 views
Skip to first unread message

Glenn Jackman

unread,
Feb 23, 2006, 10:54:33 AM2/23/06
to
I don't have my Exploring Expect book with me.

I'm spawning a program with a lot of output. I'm trying to capture it
all into a variable. I have a 'full_buffer' clause in an expect command
but it hits this error:
can't read "expect_out(buffer)": no such variable

I'm trying to reproduce it in a short script with mixed results:

==== logoutput.tcl
#!/bin/sh
#\
exec tclsh "$0" ${1+"$@"}
for {set x 0} {$x < 100000} {incr x} {
puts "line $x: hello world"
flush stdout
}
puts "finished"
==== logoutput.tcl

==== buffer.exp
#!/usr/local/bin/expect -f
log_user 0
set timeout -1
set result ""

# this program outputs about 2.4MB
spawn ./longoutput.tcl

expect {
full_buffer {
puts "have full buffer"
append result $expect_out(buffer)
puts "size of result is: [string length $result]"
exp_continue
}
eof {
puts "done"
append result $expect_out(buffer)
puts "size of result is: [string length $result]"
}
}

puts $result
==== buffer.exp


My output is like:
have full buffer
size of result is: 4001
have full buffer
size of result is: 8002
have full buffer
size of result is: 12003
have full buffer
size of result is: 16004
have full buffer
size of result is: 20005
have full buffer
size of result is: 24006
have full buffer
size of result is: 28007
done
size of result is: 31522

... and $result follows, 8 non-contiguous sections of the output

Can anyone point out what I'm doing wrong?


--
Glenn Jackman
Ulterior Designer

Uwe Klein

unread,
Feb 23, 2006, 11:42:48 AM2/23/06
to
Glenn Jackman wrote:
> have full buffer
> size of result is: 28007
> done
> size of result is: 31522
>
> ... and $result follows, 8 non-contiguous sections of the output
>
> Can anyone point out what I'm doing wrong?
>
>
size of result is: 2578412
have full buffer
size of result is: 2582416
have full buffer
size of result is: 2586420
done
size of result is: 2588901

uwe@ben > rpm -q expect
expect-5.40-27
uwe@ben > rpm -q tcl
tcl-8.4.6-26
Linux ben 2.6.5-7.111.19-default #1 Fri Dec 10 15:10:58 UTC 2004 i686 athlon i386 GNU/Linux

uwe

Glenn Jackman

unread,
Feb 23, 2006, 1:15:41 PM2/23/06
to

I'm on expect version 5.32.1, tcl 8.3.3, SunOS 5.8

Uwe Klein

unread,
Feb 23, 2006, 1:42:52 PM2/23/06
to
Glenn Jackman wrote:

>> Linux ben 2.6.5-7.111.19-default #1 Fri Dec 10 15:10:58 UTC 2004 i686 athlon i386 GNU/Linux
>>
>> uwe
>
>
> I'm on expect version 5.32.1, tcl 8.3.3, SunOS 5.8
>
>
>

from the expect HISTORY file ( the only thing i found with relevance )

2/25/02 5.35.0 Joe Eggleston <j...@arbor.xnet> noted bug in full_buffer test.
The test hadn't been I18'd properly and was testing chars
instead of bytes. Also fixed diagnostics so it printed when
it was testing full buffer even if there wasn't one.

can you upgrade? expect 5.43.0 is current : http://expect.nist.gov/

uwe

Glenn Jackman

unread,
Feb 23, 2006, 2:19:51 PM2/23/06
to
At 2006-02-23 01:42PM, Uwe Klein <uwe_klein_...@t-online.de> wrote:
> Glenn Jackman wrote:
> > I'm on expect version 5.32.1, tcl 8.3.3, SunOS 5.8
> >
> from the expect HISTORY file ( the only thing i found with relevance )
>
> 2/25/02 5.35.0 Joe Eggleston <j...@arbor.xnet> noted bug in full_buffer test.
> The test hadn't been I18'd properly and was testing chars
> instead of bytes. Also fixed diagnostics so it printed when
> it was testing full buffer even if there wasn't one.
>
> can you upgrade? expect 5.43.0 is current : http://expect.nist.gov/
>
> uwe

Thanks for that reply, that's helpful. I'm not in control of that box,
so I can't upgrade myself (wow, 5.32 is *old*). In the meantime, I have
found a workaround. The actual problem I ran into was not what I
described earlier. I have an expect clause:
full_buffer {
append result $expect_out(buffer)
exp_continue
}
and I was getting an error:
can't read "$expect_out(buffer)": no such variable
I just wrapped the appand command with:
if {[info exists expect_out(buffer)]} {...}

0 new messages