【问题标题】:Expect Script to Send Different String Outputs期望脚本发送不同的字符串输出
【发布时间】:2011-05-22 07:22:39
【问题描述】:

我有这样的东西。

expect 
 "hi"    { send "You said hi\n" } 
 "hello" { send "Hello yourself\n" } 
 "hi"    { send "2nd time you said hi\n" }

场景是我会得到一个初始响应“嗨”,然后是“你好”,然后又是“嗨”。第二次收到“hi”的响应时,我想发送一个不同的字符串。

谢谢。

【问题讨论】:

标签: unix terminal tcl expect


【解决方案1】:

你应该使用一个列表并迭代......

set responses {{You said hi} {2nd time you said hi}}
set idx 0
while {$idx < [llength $responses]} {
    expect {
     "hi"    { send [lindex $responses $idx]\n; incr idx } 
     "hello" { send "Hello yourself\n" } 
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 2013-01-01
    • 2015-01-04
    相关资源
    最近更新 更多