When channel_data
is printed with no indexing I receive a fairly standard output from a windows terminal.
I'm running this, expecting to receive the #### followed by the last 5 characters of channel_data
. Instead I'm receiving [?25h
. I assume this is some literal byte translation of something?
What's confusing me also is when I change channel_data[-5::]
to channel_data[-30::]
I get a complete different message which includes indows\system32\cmd.exe
and I think I hear some windows error noise also. What is causing this to happen?
Finally, how can I figure out what to put in my if endswith
condition, so that I'm prompted for an input once the terminal is 'loaded'? I've tried several arguments for this method, including \n new line strings. Is there just some paramiko method I should be using instead?
import paramiko
import os
import sys
host = '...'
user = '...'
passwd = '...'
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port=22, username=user, password=passwd, look_for_keys=False, allow_agent=False)
#command = os.path.abspath("...")
command = 'echo Test'
channel = ssh.invoke_shell()
channel_data = str()
host = str()
srcfile = str()
while True:
if channel.recv_ready():
channel_data+=str(channel.recv(9999))
os.system('cls')
print('#######################')
#print(channel_data)
print(channel_data[-5::])
else:
continue
if channel_data.endswith('>'):
print("Continue (y)")
user_input = str(input())
if user_input == 'y':
channel.send(command)
channel.send('\n')
else:
break