Centos 5.5或8.2上的Tcl expect脚本尝试通过ssh连接到Windows 10计算机,但可以';不能可靠地获得输出

Centos 5.5或8.2上的Tcl expect脚本尝试通过ssh连接到Windows 10计算机,但可以';不能可靠地获得输出,tcl,expect,Tcl,Expect,我有一个Tcl脚本,它在CentOS 5.5(旧的遗留工作环境)或CentOS 8.2机器上使用Expect,打开到Windows 10机器的SSH会话。我能够成功连接,但从$expect\u out(缓冲区)获取的数据不正确。我似乎只得到了我期望的输出片段,以及一些意想不到的字符,这些字符似乎会在屏幕上移动输出。当我在putty中观看脚本运行时,输入密码后,putty屏幕将被清除,窗口的第一行显示“Microsoft Windows…”,指示ssh会话的开始。然后,我可以按照我期望的命令进行操

我有一个Tcl脚本,它在CentOS 5.5(旧的遗留工作环境)或CentOS 8.2机器上使用Expect,打开到Windows 10机器的SSH会话。我能够成功连接,但从$expect\u out(缓冲区)获取的数据不正确。我似乎只得到了我期望的输出片段,以及一些意想不到的字符,这些字符似乎会在屏幕上移动输出。当我在putty中观看脚本运行时,输入密码后,putty屏幕将被清除,窗口的第一行显示“Microsoft Windows…”,指示ssh会话的开始。然后,我可以按照我期望的命令进行操作,屏幕上的输出看起来不错,但一旦到达putty窗口的底部,它就会停止。然后,在退出SSH会话之后,我的“放置”数据似乎只会覆盖已经在腻子窗口中的数据,而我的提示和光标将位于输出的中间。Windows是否发送回屏幕位置类型字符或任何会破坏我需要解析的数据的内容?在两台不同的Windows 10计算机上,此行为是相同的。从命令行手动执行此操作效果良好

Centos 5.5,tcl 8.5,预计为5.43.0

Centos 8.2.2004,tcl 8.6,预计5.45.4

我的脚本只得到“netsh wlan show int”、“ipconfig”和“dir”。这是屏幕上的输出,因为所有输出都限制在屏幕上

Microsoft Windows[版本10.0.18363.1139](c)2019年微软公司。版权所有。
戴尔拉特-7300@SR3-DELL-AX C:\Users\DELL-LAT-7300>
=============结束ipconfig数据2=============
托管网络状态:不可用
=============开始目录数据3===================
DELL-LAT-7300>ipconfig ipconfig
特定于连接的DNS后缀:
IPv6地址………:知识产权
IPv6地址………:知识产权
IPv6地址………:知识产权
临时IPv6地址……:知识产权
链接本地IPv6地址…:知识产权
IPv4地址………:知识产权
子网掩码………:知识产权
默认网关………:知识产权
知识产权
以太网适配器蓝牙网络连接2:
媒体状态………:媒体断开连接
特定于连接的DNS后缀:
戴尔拉特-7300@SR3-DELL-AX C:\Users\DELL-LAT-7300>
=============结束目录数据3===================媒体断开连接特定DNS后缀:
[user@pc-hawk~]$wlan0:
特定于连接的DNS后缀:
IPv6地址………:知识产权
IPv6地址………:知识产权
IPv6地址………:知识产权
临时IPv6地址……:知识产权
链接本地IPv6地址…:知识产权
IPv4地址………:知识产权
子网掩码………:知识产权
默认网关………:知识产权
知识产权
以太网适配器蓝牙网络连接2:
媒体状态………:媒体断开连接
特定于连接的DNS后缀:
戴尔拉特-7300@SR3-DELL-AX C:\Users\DELL-LAT-7300>dir
驱动器C中的卷是OS卷序列号是4C91-A066
C:\Users\DELL-LAT-7300目录
2020年6月21日09:23下午。2020年6月21日09:23下午
2019年9月16日上午10:31 idlerc
============启动netsh数据1==========================netsh wlan显示int
我的Tcl Expect脚本:

package require Expect
set client_ip "10.10.10.203"
set username "username"
set password "password"
set rawdata1 ""
set rawdata2 ""
set rawdata3 ""
set rawdata4 ""
set timeout 10
spawn ssh $client_ip -l $username
expect {
    timeout {
        expect *;
        exit;
    }
    -nocase "(yes/no)?" {
        after 500
        exp_send "yes\r\n"
        exp_continue
    }
    -nocase "password:" {
        after 500
        exp_send "$password\r\n"
        exp_continue
    }
    -nocase ">" { }
}
catch {expect ">"}
catch {expect *}
set rawdata1 ""
after 2000
exp_send "netsh wlan show int\r\n"
expect {
    timeout   { }
    -re ">" { }
}
set rawdata1 $expect_out(buffer)
catch {expect ">"}
catch {expect *}
after 2000
exp_send "ipconfig\r\n"
expect {
    timeout   { }
    -re ">" { }
}
set rawdata2 $expect_out(buffer)
catch {expect ">"}
catch {expect ">"}
catch {expect *}
after 2000
exp_send "dir\r\n"
expect {
    timeout   { }
    -re ">" { }
}
set rawdata3 $expect_out(buffer)
catch {expect ">"}
catch {expect ">"}
catch {expect ">"}
catch {expect *}
after 2000
exp_send "exit\r\n"
puts "\n\n==========start netsh data 1==============\n$rawdata1\n===========end netsh data 1=============\n\n"
puts "\n\n==========start ipconfig data 2==============\n$rawdata2\n===========end ipconfig data 2=============\n\n"
puts "\n\n==========start dir data 3==============\n$rawdata3\n===========end dir data 3=============\n\n"
exit
根据反馈,从od-c和expect-d的输出中,我看到了一些转义字符(033或0x1b),后跟]和一系列字符。我怀疑这就是为什么我的输出在整个屏幕上。但是expect-d的输出看起来像是我得到了一堆转义字符,而不是我的有效数据。即使我能清除这些字符,看起来我的数据也不在那里。关于如何从Win10中获取有效数据有什么建议吗

我希望这是“netsh wlan show int” 系统上有1个接口:

Name                   : wlan0
Description            : Intel(R) Wi-Fi 6 AX200 160MHz
GUID                   : 
Physical address       : mac
State                  : disconnected
Radio status           : Hardware On
                         Software On

Hosted network status  : Not available
expect-d中的代码段,其中我发送了“netsh wlan show int\r”

期望:有” \r\n\u001b[2J\u001b[?25l\u001b[m\u001b]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\u001b[H\u001b]0;c:\windows\system32\cmd.exe\u0007\u001b[?25h\u001b[?25lMicrosoft Windows[版本10.0.8363.1198]\u001b[18X\u001b[18C\r\n(c)2019 微软公司。版权所有 保留。\u001b[9X\u001b[9C\r\n\u001b[61X\u001b[61C\r\n卸载lat-7300@SR3-戴尔AX C:\Users\DELL-LAT-7300>\u001b]0;管理员: c:\windows\system32\cmd.exe\u0007\u001b[?25h”(spawn\u id exp6)匹配 全局模式(是/否)??否?密码:?否“7300>?是预期:设置 expect\u out(0,字符串)“7300>”expect:set expect\u out(spawn\u id)“exp6” expect:设置expect\u out(缓冲区)” \r\n\u001b[2J\u001b[?25l\u001b[m\u001b]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\u001b[H\u001b]0;c:\windows\system32\cmd.exe\u0007\u001b[?25h\u001b[?25lMicrosoft Windws[Version 10.0.18363.1198]\u001b[18X\u001b[18C\r\n(c)2019 微软公司。版权所有 保留。\u001b[9X\u001b[9C\r\n\u001b[61X\u001b[61C\r\n卸载lat-7300@SR3-戴尔-X C:\Users\DELL-LAT-7300>“发送:发送”netsh wlan show int\r“到{ exp6}

预期:是否“\u001b]0;管理员: c:\windows\system32\cmd.exe\u0007\u001b[?25h”(繁殖id