Tcl 超时不';t与'-re';expect脚本中的标志

Tcl 超时不';t与'-re';expect脚本中的标志,tcl,expect,Tcl,Expect,我试图让expect脚本工作,当我使用-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 {

我试图让expect脚本工作,当我使用-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"}
}
是的,问题中出现的“-re”标志将应用于expect命令中的每个模式。因此,“timeout”模式变为“-re timeout”,失去了它的特殊性。

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

Figured it out:

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