如何修复'发送:spawn id exp4在执行" exp_send -s" $ cmd \ r""时未打开'错误

时间:2015-10-19 09:57:14

标签: tcl putty spawn

我的TCL文件包含如下代码,

proc executeCmd {cmd {file ""}} {
    set out ""
    set output ""
    set send_slow {20 0.1}
    set adminFlag 0
    exp_send -s "$cmd\r"
    for {set i1 0} {$i1 < 12} {incr i} {
            set intimeout 0
            expect {
                    # other options to check 'hostname', 'more', 'press any to continue' regexes
                    # ...
                    -regexp {^(.*)Press any key to continue.*$} {
                        set output [cleanOutput $expect_out(buffer)]
                        if {[regexp -- {\w+} $file]} {
                            append out $output
                            flush $fo
                            flush $clf
                        } else {
                            append out $output
                        }
                        exp_sleep 0.1
                        exp_send -s " "
                        exp_continue
                    }

                    timeout {
                            #log_msg INFO "TIMED OUT...."
                            puts "TIMED OUT"
                            set intimeout 1
                            puts "Executing $cmd >>> waiting for response from $hostname"
                    }
            }
            if {$intimeout} {
                    exp_send -s " "
            } else {
                    break
            }
    }
    return $out
}

spawn $plinkLoc -telnet $routerIP -P $routerPort
set out [executeCmd "term width 0"]

通过命令提示符执行此TCL后,我面临错误,

send: spawn id exp4 not open
    while executing
"exp_send -s "$cmd\r""
    (procedure "executeCmd" line 28)
    invoked from within
"executeCmd "term width 0""
    invoked from within
"set out [executeCmd "term width 0"]""

TCL代码中的第28行是&#39;设置&#39;在'executeCmd&#39;之前的陈述proc,已更新文件以供查询。

1 个答案:

答案 0 :(得分:0)

您必须将spawn_id传递给该过程,或将spawn_id声明为global

在程序

中添加此行
global spawn_id