期待意外 [英] Expecting the Unexpected in Expect
本文介绍了期待意外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当看到除预期之外的其他信息时,我该如何给出预期的指示?
How can I give an instruction to expect, when it sees anything other than what it expects?
例如,我尝试自动进行登录.除了成功尝试之外,我还需要脚本向我发送错误消息.我如何期待意外的输出? (我知道一些结果,例如连接被拒绝或密码错误,但是我想抓住一切)
Example, I attempt to automate a login. For anything other than a successful attempt, I need the script to mail me an error. How do I expect unexpected output? (I know some outcomes, like connection denied, or wrong password, but I want to catch everything)
推荐答案
尝试如下:
set timeout 10; # set a reasonable timeout
# expect and send username/password ...
set success 0
set err_msg ""
expect {
"Login success!" {
set success 1
}
eof {
set err_msg $expect_out(buffer)
}
timeout {
expect *
set err_msg $expect_out(buffer)
}
}
if {! $success} {
send_mail $err_msg
exit 1
}
这篇关于期待意外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文