Expect中的`expect_before`命令有什么用? [英] What's the usage of `expect_before` command in Expect?

查看:708
本文介绍了Expect中的`expect_before`命令有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

医生说:

的参数与expect相同,但是会立即返回.

takes the same arguments as expect, however it returns immediately.

但是立即返回"是什么意思?

But what does it mean by "returns immediately" ?

此命令的用途是什么?

推荐答案

您生成了一个图片,该图片会随机询问您确定[yn]吗?"
想象一下,这个程序有100个问题需要回答.

Image you have spawned a program that, say, randomly asks "Are you sure [yn]?"
Imagine this program has 100 questions that need to be answered.

您不希望对这100个问题中的每一个都有条件期待一个您确定"问题.

You don't want to have to conditionally expect an "Are you sure" question for each of those 100 questions.

期望让您做到:

spawn /some/annoying/program

expect_before {
    "Are you sure \[yn]?" {
        send "y\r"
        exp_continue
    }
}

expect "first question"
send "first answer\r"
# and so on.

现在您可以覆盖其中:期望隐式expect_before代码添加到每个 expect命令中.

Now you are covered: expect implicitly adds the expect_before code into each expect command.

这篇关于Expect中的`expect_before`命令有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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