如何使用expect_out捕获expect脚本命令的输出?

时间:2013-05-08 18:41:25

标签: expect

#!/usr/bin/expect -f
spawn telnet IP PORT
expect "Escape character is '^]'"
send loadtime
set accum {} 
expect {
    -regexp {..*} {
        append accum "${accum}$expect_out(0,string)" 
        exp_continue
    }
}
puts $accum

loadtime命令的输出类似于“加载时间:2.45” 但是,在执行脚本时,$ accum仅显示“loadtime”而不显示“Load Time:2.45”

如何在变量或本地文件中捕获loadtime命令的输出?

1 个答案:

答案 0 :(得分:0)

您忘记按Enter键:send "loadtime\r"