任何人都可以看看并建议为什么以下代码段不执行 if 语句的两个分支?脚本不会抛出任何错误。它只是到达期望线并等待它超时。arg1 只是命令行中的一个参数。
set arg1 [lindex $argv 0]
set strname "teststring"
expect {
"prompt#" {
if { [string compare $arg1 $strname] != 0 } {
send "strings different\r"
} else {
send "strings same\r"
}
}
default abort
}
Run Code Online (Sandbox Code Playgroud)
提前致谢。
编辑:
编辑以显示正确的结构。
Expect 是 Tcl 的扩展,Tcl 非常讲究空格:
...
# need a space between the end of the condition and the beginning of the true block
if { [string compare $arg1 $strname] != 0 } {
...
# the else keyword needs to be on the same line as the closing bracket of the true block
} else {
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4711 次 |
| 最近记录: |