期望脚本发送不同的字符串输出

时间:2011-05-22 07:22:39

标签: unix terminal tcl expect

我有类似的东西。

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

情节是我会得到一个初始响应'hi',然后'hello',然后'hi'再次响应。我第二次收到'hi'的回复,我想发送一个不同的字符串。

感谢。

1 个答案:

答案 0 :(得分:3)

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

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" } 
    }
}
相关问题