I'm Trying to make a real time SSH Library, but as usually getting stuck on things, I have taken this code from Long-running ssh commands in python paramiko module (and how to end them). But this code doesn't prints the whole output.
I guess that when the while loop exits on channel.exit_status_ready() the channel still have data to read. I've been trying to fix this but the fix was not on all inputs.
How can I make this work to print all kind of commands?
import paramiko
import select
client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect('host.example.com')
channel = client.get_transport().open_session()
channel.exec_command("cd / && ./test.sh")
while True:
if channel.exit_status_ready():
break
rl, wl, xl = select.select([channel], [], [], 0.0)
if len(rl) > 0:
print channel.recv(1024)
test.sh:
echo 1
wait 1
echo 2
wait 1
echo 3
Output:
1
2
Process finished with exit code 0
Thanks.