2011-05-22 60 views
0

我有这样的事情。期望脚本发送不同的字符串输出

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

该场景是我会得到一个初步的响应'嗨',然后'你好',然后'嗨'了。第二次,我收到'嗨'的回应,我想发送一个不同的字符串。

谢谢。

+0

这是什么语言? – Oded 2011-05-22 07:26:50

+0

http://en.wikipedia.org/wiki/Expect – Jordan 2011-05-22 07:27:54

回答

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" } 
    } 
}