【发布时间】: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”的响应时,我想发送一个不同的字符串。
谢谢。
【问题讨论】:
我有这样的东西。
expect
"hi" { send "You said hi\n" }
"hello" { send "Hello yourself\n" }
"hi" { send "2nd time you said hi\n" }
场景是我会得到一个初始响应“嗨”,然后是“你好”,然后又是“嗨”。第二次收到“hi”的响应时,我想发送一个不同的字符串。
谢谢。
【问题讨论】:
你应该使用一个列表并迭代......
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" }
}
}
【讨论】: