Tcl 当expect\u out(buffer)size的内部缓冲区大小超过时,如何从expect获得完整的输出?
我不知道发生了什么,但我没有得到远程命令执行的完整输出,可能是因为预期内部缓冲区正在执行Tcl 当expect\u out(buffer)size的内部缓冲区大小超过时,如何从expect获得完整的输出?,tcl,expect,Tcl,Expect,我不知道发生了什么,但我没有得到远程命令执行的完整输出,可能是因为预期内部缓冲区正在执行 proc SendCommands { Commands } { global prompt log errlog foreach element [split $Commands ";"] { expect {
proc SendCommands { Commands } {
global prompt log errlog
foreach element [split $Commands ";"] {
expect {
-re $prompt
{send -- "$element\r"}
}
set outcome "$expect_out(buffer)"
foreach line [split $outcome \n] {
foreach word [regexp -all -inline {\S+} $line] {
if {( [string index [string trimleft $line " "] 0 ] == "%")} {
puts "$outcome"
exit 1
}
}
}
puts "$outcome"
}
}
set timeout 30
foreach host [ split $hosts "\;" ] {
spawn ssh -o "StrictHostKeyChecking no" "$username@$host"
match_max 10000000
expect {
timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
eof { send_user "\nSSH failure for $host\n"; exit 1 }
"*?assword:*"
{
send -- "$password\r"
}
}
expect {
timeout { send_user "\nLogin incorrect\n"; exit 1 }
eof { send_user "\nSSH failure for $host\n"; exit 1 }
-re "$prompt"
{ send -- "\r" }
}
set timeout 300
SendCommands "$Commands"
}
我是这样执行的:
./sendcommand aehj SWEs-elmPCI-B-01.tellus comnet1 "terminal length 0;show int description" "(.*#)$"
只有当我删除log user 0
时,我才能获得完整的输出,但是当我在上面的函数sendcommands中使用puts命令时,我得到了大约90%的输出,其中10%的输出
未显示末尾尾随数据的长度
我的一个想法是在expect中使用regex的否定,但它似乎不起作用
expect {
-re ! $prompt
{puts $expect_outcome(buffer)}
}
编辑:当它执行5到7次时,我得到了所有的输出。经过一点搜索,我找到了这个,看起来很有效,但请告诉我任何执行或更好的答案: 然后我设置match_max=1000
expect {
-re $prompt
{send -- "$element\r"}
full_buffer {
append outcome $expect_out(buffer)
exp_continue
}
}
append outcome $expect_out(buffer)
puts $outcome
但是,当我设置match_max=10000或100时,它再次失败