Timeout doesn't work with '-re' flag in expect script

倾然丶 夕夏残阳落幕 提交于 2019-12-11 14:09:13

问题


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

回答1:


Figured it out:

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



回答2:


Yes, the "-re" flag as it appears in your question will apply to every pattern in the expect command. So the "timeout" pattern becomes "-re timeout", losing its specialness.



来源:https://stackoverflow.com/questions/136554/timeout-doesnt-work-with-re-flag-in-expect-script

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