So because sharing is caring , I resolved the issue for the PARAMIKO with continuous output like this (ignore the index and replace stuff, issues proprietary to my device):
"elif action == "icmd":
cmd = command
channel = ssh.get_transport().open_session()
channel.exec_command(cmd)
channel.set_combine_stderr(True)
index = 0
a = "" # list to be filled with output of the commands.
while True:
if channel.exit_status_ready():
break
o = channel.recv(2048).decode("utf-8")
if o:
a += o
if "\n" in o:
b = a.split("\n")
a = b[-1]
b.pop()
for x in b:
print(x.replace("●", "").replace("└─", ""), flush=True)
index += 1
if index == 0 and len(o) > 0:
print(o.replace("●", "").replace("└─", ""), flush=True)
if index == 0 and len(o) == 0:
print(f"Your command '{cmd}' did not returned anything! ")
channel.close()
ssh.close()
"
I chose the split and pop things because when using commands like : traceroute www.google.com , for example, the output was splited into separate rows.
Also, I integrated a shell, for interactive input/output with the device, like this :
elif action == "shell":
channel = ssh.invoke_shell()
cmd = command
print("Shell started")
print(channel.recv(2048).decode())
while True:
if channel.exit_status_ready():
print("Session Ended!")
break
try:
cmd = input(cmd)
channel.send(f"{cmd}\n".encode())
time.sleep(1)
output = channel.recv(2048).decode("utf-8")
print(output.replace("●", "").replace("└─", ""), flush=True)
if cmd == "exit":
break
except KeyboardInterrupt:
break
channel.close()
ssh.close()
Enjoy it !