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

expect -notransfer option

177 views
Skip to first unread message

derek....@csr.com

unread,
Aug 22, 2007, 10:56:58 AM8/22/07
to
As I under stand it the -notransfer option to expect keeps the buffer
intact after matching a patern.
Now having written a procedure to look for several patterns in the
buffer I'm seeing unexplained behaviour in that the buffer is not
refreshed with new input even after starting a new expect pattern
match and the buffer needs to be emptied before it will be updated.

Is this expected behaviour or a bug?

Is there a way to force the updating of the buffers keeping the
previous content.

Thanks

Derek

sample code.

.
.
.
.

set timeout 1
set stop1
while { $stop } {
# Now look at each pattern in turn
foreach pattern $patt_list {
expect {
-notransfer -re $pattern {
# we have found one of the list, lets
remove it
# to speed things up a little
set patt_list [ ldelete $patt_list
$pattern ]
if { $patt_list == -1 } {
# Hhm an error deleting from the list
# see below in clear buffer errors
for handling this
set ret_val -2
set stop 0
};# End if patt_list
}
timeout { puts "Here in timeout lookig for
\"$pattern\""}
};#End of expect
};#End foreach
# do some check to get out of the while
.
.
};#End while

derek....@csr.com

unread,
Aug 23, 2007, 6:29:09 AM8/23/07
to
On 22 Aug, 15:56, derek.phi...@csr.com wrote:
> As I under stand it the -notransfer option to expect keeps the buffer
> intact after matching a patern.
> Now having written a procedure to look for several patterns in the
> buffer I'm seeing unexplained behaviour in that the buffer is not
> refreshed with new input even after starting a new expect pattern
> match and the buffer needs to be emptied before it will be updated.
>
> Is this expected behaviour or a bug?
>
> Is there a way to force the updating of the buffers keeping the
> previous content.
>
> Thanks
>
> Derek
>
{snip}
I have always thought that the default match_max was 10000, I don't
know why, but browsing through the code I see it is 2000.
If I set match_max to 10000 then I get around my immediate problem
above but still have an issue with the buffer not refilling while
using -notransfer

Derek

Bezoar

unread,
Aug 30, 2007, 12:44:08 PM8/30/07
to

you should use the expect key word full_buffer which is activated
every time
the max_match limit is reached and cache your own results. I would not
use
the -notransfer option because if it does as you say it prevents the
clearing
of the expect_out array and you can manipulate it then you may
inadvertantly
match another of your targets and it will be very difficult to debug.
If at all
possible get all the data into your own buffers then post process it.
I wrote an example for another poster for using the full_buffer
target. It gets
a spawn id from a ssh login and submits the command. The command he
was
useing was ps -aef which went beyond 2000 bytes ( in past it had been
10000).
You can set the size for the match buffer larger but it is better to
just handle it like
below.

proc sendCommand { spawnid retbuffer command prompt { timeout -1 } }
{
set retval 0
upvar $retbuffer buffer
exp_internal 0; # set to one for extensive debug
log_user 0 # set to one to watch action
set bad 0;
exp_send -i $spawnid -- "$command\r"
expect {
-i $spawnid
full_buffer {
send_user " buffer is full... caching"
append buffer $expect_out(buffer);
set bad 0
exp_continue;
}
-re "$prompt" {
# get rid of command at top and prompt at bottom in response
append buffer $expect_out(buffer);
set buffer [string trim [ join [lrange [split $buffer "\n"] 1
end-1 ] "\n" ] ]
set bad 0 ;
}
timeout {
send_user "timeout"
append buffer "\ntimeout"
set bad 1
}
eof {
send_user "Eof detected"
append buffer "\nEOF detected"
set bad 1;
}
}
return $bad;
}

Carl

0 new messages