I get the error "can't set "::exp::winnt_debug": parent namespace doesn't exist" when I try to run my expect script using the C implementation of expect interpreter on Windows (expect543.dll). However the same script works fine if I run it through the ActiveState command tclsh...

The statement "set ::exp::winnt_debug 1" in the script is the cause of the error. Any idea what might be the reason and how to resolve it?

Please find the code below

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 .."
有帮助吗?

解决方案

There may be several implementations of Expect for Windows (unlike the Unix version, which has been stable for ages) and it sounds like the details of how they are implemented internally varies quite a bit between them. That's not especially surprising. Furthermore, the variable ::exp::winnt_debug is absolutely internal to a particular implementation.

The immediate fix is to change the line with the error to this:

catch {set ::exp::winnt_debug 1}

Like that, if it fails, it fails silently and won't cause the rest of the program to not run. (Enabling debugging shouldn't make any difference to whether the code runs!)

More generally, either use the ActiveState build (and work out how to package things together in the right way, bearing mind that critical dependency) or stop referring to internal features of it. It's very bad form to be poking your fingers inside the implementation of a package, as nobody ever gave a commitment to support them.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top