tcl - 期望不匹配
问题描述
我有一个可以运行的期望脚本;它包含以下几行:
expect "\[Y\]\> "
send "n\r"
我正在与之交互的操作系统发生了变化,我现在有一个混合的盒子环境。有些现在有“[Y]>”,有些有“[1]>”,我正在尝试处理。
我尝试将代码更改为:
expect {
"\[Y\]\> " { send "n\r";exp_continue }
"\[1\]\> " { send "2\r";exp_continue }
}
但是,在调试中运行我看到:
"Choose the password option:
1. Mask passwords
2. Plain passphrases
[1]>
expect: does "s...ses\r\n[1]> " (spawn_id exp5) match glob pattern "[Y]> "? no
"[1]> "? no
expect: timed out"
我不明白为什么修改后的代码不起作用,对于“[Y]>”或“[1]>”,当“[Y]>”在引入“else”语句之前被匹配时。
解决方案
问题在于转义方括号,这是Tcl
.
# Using braces for pattern
expect {
{\[Y]>} {puts Y}
{\[1]>} { puts 1}
}
# or
# Using double quotes
expect {
"\\\[Y]>" {puts Y}
"\\\[1]>" { puts 1}
}
我们不必转义右括号]
和符号>
推荐阅读
- javascript - supertest 在每次测试中更改 url
- c# - 在pdf文件中隐藏datagridview中的列
- macos - applicationShouldTerminate:系统重启时不调用
- android - 将颤振模块嵌入到android原生
- excel - 返回跨列 >= 指定日期的最小日期
- c - 是否可以在 C 中找到变量的数据类型?
- sql - 如何找到停止删除表的触发器
- command-line-interface - Microsoft AppCenter CLI - 公共 URL 创建
- electron - 调试电子应用程序
- ios - 在 QuickLook 中打开 USDZ 文件