Tcl exp::winnt\u调试父命名空间错误

Tcl exp::winnt\u调试父命名空间错误,tcl,expect,activestate,Tcl,Expect,Activestate,当我尝试在Windows上使用expect解释器的C实现(expect543.dll)运行expect脚本时,出现错误“无法设置”::exp::winnt\u debug”:父命名空间不存在。 但是,如果我通过ActiveState命令tclsh运行同一个脚本,它就可以正常工作 脚本中的语句“set::exp::winnt_debug 1”是导致错误的原因。 你知道原因是什么以及如何解决吗 请在下面查找代码 package require Expect set ::exp::winnt_debu

当我尝试在Windows上使用expect解释器的C实现(
expect543.dll
)运行expect脚本时,出现错误“
无法设置”::exp::winnt\u debug”:父命名空间不存在。
但是,如果我通过ActiveState命令tclsh运行同一个脚本,它就可以正常工作

脚本中的语句“
set::exp::winnt_debug 1
”是导致错误的原因。 你知道原因是什么以及如何解决吗

请在下面查找代码

package require Expect
set ::exp::winnt_debug 1
set prompt "R4#"
set more " --More--"
expect -timeout 10 "$prompt"
set output [open result.txt "w"]
set running 1
spawn plink -telnet "144.21.12.45" -P 2004
send "enable\r"
send "\r"
send "show running-config\r"
send "\r"
while { $running  > 0 } {
expect {
    "\n"    { puts -nonewline $output "$expect_out(buffer)" }
    "$more"    {send " "}
    "lines *-* " { send " " }
    #"$prompt"   { set running 0 }
    eof     { set running 0 }
    timeout     { set running 0 }
}

}
puts "output is .."

Expect for Windows可能有几种实现(与Unix版本不同,Unix版本已稳定多年),听起来它们内部实现方式的细节在它们之间差异很大。这并不特别令人惊讶。此外,变量
::exp::winnt_debug
绝对是特定实现的内部变量

立即修复的方法是将出现错误的行更改为:

catch {set ::exp::winnt_debug 1}
这样,如果它失败了,它会无声地失败,不会导致程序的其余部分不运行。(启用调试不会影响代码是否运行!)


更一般地说,要么使用ActiveState构建(并考虑如何以正确的方式将事物打包在一起,记住关键的依赖关系),要么停止引用它的内部特性。在包的实现中插手指是非常糟糕的,因为从来没有人承诺支持它们。

您如何激活Expect代码<代码>包装要求
<代码>加载?我使用命令“package require expect”将其激活。已添加代码供您参考。