题
我正在尝试使用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"}
}
解决方案
Figured it out:
expect {
timeout { puts "timed out at step 2" ; exit }
-re "foo " { puts "it said foo at step 2"}
}
其他提示
是的,“ - 是”您的问题中出现的标志将应用于expect命令中的每个模式。所以“超时”是指“超时”。模式变为“-re timeout”,失去其特殊性。
不隶属于 StackOverflow