预期脚本中的超时不与'-re'标志一起使用 [英] Timeout doesn't work with '-re' flag in expect script

查看:61
本文介绍了预期脚本中的超时不与'-re'标志一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使期望脚本起作用,并且当我使用-re标志(以调用正则表达式解析)时,"timeout"关键字似乎不再起作用.当运行以下脚本时,我得到消息在步骤1超时",然后启动步骤2",然后它超时,但是没有打印在步骤2超时",我得到一个新的提示. /p>

想法?

#!/usr/bin/expect --

spawn $env(SHELL)
match_max 100000

set timeout 2

send "echo This will print timed out\r"
expect  {
    timeout { puts "timed out at step 1"  }
    "foo " { puts "it said foo at step 1"}
}

puts "Starting test two\r"

send "echo This will not print timed out\r"
expect  -re {
    timeout { puts "timed out at step 2" ; exit }
    "foo " { puts "it said foo at step 2"}
}

解决方案

Figured it out:

expect  {
    timeout { puts "timed out at step 2" ; exit }
    -re "foo " { puts "it said foo at step 2"}
}

I'm trying to get an expect script to work, and when I use the -re flag (to invoke regular expression parsing), the 'timeout' keyword seems to no longer work. When the following script is run, I get the message 'timed out at step 1', then 'starting step 2' and then it times out but does NOT print the 'timed out at step 2' I just get a new prompt.

Ideas?

#!/usr/bin/expect --

spawn $env(SHELL)
match_max 100000

set timeout 2

send "echo This will print timed out\r"
expect  {
    timeout { puts "timed out at step 1"  }
    "foo " { puts "it said foo at step 1"}
}

puts "Starting test two\r"

send "echo This will not print timed out\r"
expect  -re {
    timeout { puts "timed out at step 2" ; exit }
    "foo " { puts "it said foo at step 2"}
}

解决方案

Figured it out:

expect  {
    timeout { puts "timed out at step 2" ; exit }
    -re "foo " { puts "it said foo at step 2"}
}

这篇关于预期脚本中的超时不与'-re'标志一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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