问题
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