paramiko recv() returning multiple echos of command

↘锁芯ラ 提交于 2019-12-23 04:14:31

问题


I am trying to talk to a WIN10 machine (with OpenSSH installed). For most part it works but when i send a command (via send) and use read channel(via recv), the data i get back has some strange echos for command i sent. Seems like channel has the full command and then it goes to server byte by byte. And all these stages are logged in recv. Below is is a sample code

PS: Issue not seen if i talk to a Linux machine

isession = paramiko.SSHClient()
isession.set_missing_host_key_policy(paramiko.AutoAddPolicy())
isession.connect(ip, username=user, password=pwd)
ishell = isession.invoke_shell()
ishell.send("set prompt=ICUSTOMPROMP$G" + "\n")
aa = ishell.recv(65535).encode("utf-8")
strip_ansi = re.compile(r'\x1B[@-_][0-?]*[ -/]*[@-~]')
bb = strip_ansi.sub('', aa)

the OP (which is bb) is

Microsoft Windows [Version 10.0.17134.858]                                      
\n(c) 2018 Microsoft Corporation. All rights reserved.                            
\n\nuser@YYYY C:\\Users\\XXX>                                                    
set prompt=ICUSTOMPROMP$G                           et 
prompt=ICUSTOMPROMP$G                           t prompt=ICUSTOMPROMP$G                            
prompt=ICUSTOMPROMP$G                           prompt=ICUSTOMPROMP$G                           
rompt=ICUSTOMPROMP$G                           ompt=ICUSTOMPROMP$G                           
mpt=ICUSTOMPROMP$G                           pt=ICUSTOMPROMP$G                           
t=ICUSTOMPROMP$G                           =ICUSTOMPROMP$G                           
ICUSTOMPROMP$G                           CUSTOMPROMP$G                           
USTOMPROMP$G                           STOMPROMP$G                           
TOMPROMP$G                           OMPROMP$G                           
MPROMP$G                           PROMP$G                           
ROMP$G                           OMP$G                           MP$G                           
P$G                           $G                           G                           
\n\nICUSTOMPROMP> 

expected OP should be that my command should be printed just once.

Is there something i can do to fix this? Or is this some issue with win10 open ssh? Has anyone tried sending commands to WIN10 via paramiko

来源:https://stackoverflow.com/questions/57532222/paramiko-recv-returning-multiple-echos-of-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!