期望脚本发送不同的字符串输出 [英] Expect Script to Send Different String Outputs

查看:61
本文介绍了期望脚本发送不同的字符串输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的东西.

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

这种情况是,我将得到一个初始响应"hi",然后是"hello",然后是"hi".第二次收到"hi"响应时,我想发送一个不同的字符串.

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.

谢谢.

推荐答案

您应该使用列表并进行迭代...

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

这篇关于期望脚本发送不同的字符串输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆