Expect Script to Send Different String Outputs

只愿长相守 提交于 2020-01-06 14:51:09

问题


I have something like this.

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

The scenario is I will get a initial response 'hi', then 'hello', then 'hi' again. The second time I get a response of 'hi', I want to send a different string.

Thanks.


回答1:


You should use a list and iterate...

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


来源:https://stackoverflow.com/questions/6086617/expect-script-to-send-different-string-outputs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!