预期脚本中的超时不与'-re'标志一起使用
时间:2020-03-06 14:45:15 来源:igfitidea点击:
我试图使一个期望脚本起作用,并且当我使用-re标志(以调用正则表达式解析)时," timeout"关键字似乎不再起作用。当运行以下脚本时,我得到消息"在步骤1超时",然后"开始步骤2",然后它超时,但是没有打印"在步骤2超时",我得到一个新提示。
有想法吗?
#!/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"标志将应用于Expect命令中的每个模式。因此,"超时"模式变为" -re超时",从而失去了其特殊性。

