在期望脚本中,超时不适用于'-re'标志

时间:2008-09-25 22:19:24

标签: tcl expect

我正在尝试使用expect脚本,当我使用-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"}
}

2 个答案:

答案 0 :(得分:2)

Figured it out:

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

答案 1 :(得分:2)

是的,问题中出现的“-re”标志将适用于expect命令中的每个模式。所以“超时”模式变成“-re timeout”,失去了它的特殊性。