Re: What if Expect buffer overflows
- From: "Bezoar" <cwjolly@xxxxxxxxx>
- Date: 14 Sep 2006 13:57:11 -0700
Arun
Can you provide the code ( suitably abridged ) that you are using. Also
what form are you expecting your data. Is it all on one line? or are
there linefeeds/carriage returns after each port is returned. You
should also be aware that if a timeout or and eof occures there may be
data in the xpect_out(buffer). You should make sure you capture the
expect_out(buffer) when eof and timeout events happen. Not doing this
could explain why you are not getting the last part of your data. Also
the timeout refers not to the total time but the time before a match
occures so if your port data comes every 3 seconds then a timeout of 10
is more reasonable. I wrote some test code below that you can use to
run your command line. I ran this on a Linux box just replace "ls -la"
with your command and see what happens. In the first case you use a
regular expression to get 100 characters at a time thus you are well
within the expect buffer limits. The second case gets 10 characters at
a time. The third the whole thing at once. and the last test case is
one line at a time. Just update the testcase proc with an appropriate
test case. You will notice in the 100/10 chunk at a time test cases
that in fact some data is returned when eof if detected. ( You see
"<eof>" in the returned output. Similarity you may see "<timeout>" .
Try the code in the example below to see if it works for your command.
..
#!/opt/usr/bin/tclsh8.4
# either require expect or use expect instead of tclsh above
package require Expect
proc printtest { testnum command exit_status buff match_count} {
puts "+[string repeat "=" 79 ]"
puts "| Command : $command $testnum regexp test"
puts "| exited with exit status: $exit_status"
puts "| spawn process pid : [ lindex $exit_status 0 ] "
puts "| expect spawn id : [ lindex $exit_status 1 ]"
puts "| expect waited on process successfully? : [ expr [ lindex
$exit_status 2]?"No":"Yes" ]"
puts "| spawn process succeeded?: [ expr [lindex $exit_status 3
]?"No":"Yes" ]"
puts "| number of times expect matched regexp : $match_count"
puts "|returned:\n+[string repeat "-" 79 ]\n$buff\n"
puts "[string repeat "=" 79 ]"
}
proc testcase { testcase command regexpression } {
global spawnid
log_user 0; # set to 0 to hide command output from user
exp_internal 0; # put 1 here and expect will vomit output!
set pid [ eval spawn $command ]
set myid $spawn_id; # good habit to save spawn_id
set timeout 1
set buff ""
set match_count 0
expect {
-i $myid
-re $regexpression {
incr match_count
send_user "."
# if you change append to lappend below when it
# prints out below you can see the chunks it gets
append buff $expect_out(buffer);
exp_continue; # loop again
}
timeout {
send_user "timeout\n"
# if you timeout
append buff <timeout>$expect_out(buffer);
}
eof {
send_user "eof\n"
append buff "<eof>$expect_out(buffer)";
}
}
catch { exp_wait -i $myid -nowait } exit_status
# this may be redundant but because of -nowait we have to ensure
# we get the catch the childs signal otherwise its zombieville
# ( i.e. produces a zombie )
catch { exp_close -i $myid }
printtest "Chunk regexp test" "ls -la" $exit_status $buff
$match_count
}
testcase "100 Char Chunk regexp test" "ls -la" {.{100}}
testcase "10 Char Chunk regexp test" "ls -la" {.{10}}
testcase "all at once regexp test" "ls -la" {^.$}
testcase "line at a time regexp test" "ls -la" {.*[\n\r]+}
Arun Gupta wrote:
I am send a cli command to my equipment using expect script.
The script is OK when the response of cli command sent to the equipment
is small.
There is a command whose response is very big ( it retuned me status of
100 of ports of my eqipment and may take 1 minutes to display the whole
result).
I have set timeout of 100 sec, and after sending that command I am
expecting a correct string, but after displaying small amount of data ,
the script is entering the next loop ( which it should enter only after
displaying all the info.). I have also increased the buffer size to
10000 char, but still no effect.
Can anybody please guide what should I do to display the whole info?
.
- References:
- What if Expect buffer overflows
- From: Arun Gupta
- What if Expect buffer overflows
- Prev by Date: tcllib pop3: returning too many newlines?
- Next by Date: Problem with exec command
- Previous by thread: What if Expect buffer overflows
- Next by thread: txrx-package
- Index(es):
Relevant Pages
|
|