Tcl 存储expect脚本的所有命令的输出

Tcl 存储expect脚本的所有命令的输出,tcl,expect,Tcl,Expect,我对TCL脚本有点陌生。我编写了一个expect shell脚本,其中有多个expect send命令 我知道expect_out(buffer)只存储上一个命令的输出,但我的目标是存储脚本中使用的所有命令的输出 我该怎么做 感谢对每个命令使用$expect\u out(buffer),如下所示: send "show interface\r" ; # 1st command expect "*#" set a $expect_out(buffer) send "show vlan\r" ;

我对TCL脚本有点陌生。我编写了一个expect shell脚本,其中有多个expect send命令

我知道expect_out(buffer)只存储上一个命令的输出,但我的目标是存储脚本中使用的所有命令的输出

我该怎么做

感谢对每个命令使用
$expect\u out(buffer)
,如下所示:

send "show interface\r"  ; # 1st command
expect "*#"
set a $expect_out(buffer)
send "show vlan\r"  ; # 2nd command
expect "*#"
set b $expect_out(buffer)
send "show ip interface brief\r"  ; # 3rd command
expect "*#"
set c $expect_out(buffer)
在这里,您可以看到捕获到各个变量的所有命令输出

puts $a
puts $b
puts $c

嘿,谢谢,真管用!!您还可以提供一个示例,说明如何使用$expect(0,字符串)或$expect(1,字符串)等等……expect将匹配的字符存储在
expect\u out(0,字符串)
中。对于
expect(1,string)
expect(2,string)
等,它们用于存储与子模式匹配的字符串。当脚本中有正则表达式时,这非常有用。