I am trying to read the output of a long-running ssh command continuously. I understand that exec_command
is non-blocking. But as soon as I use stdout.readlines()
it becomes blocking. I don't want to wait for 10 minutes for my ssh command to finish to read all the output lines. I want to get the output as soon as the ssh command writes in stdout. Is there a way to do it?
import paramiko
#import select
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname,username=username,password=password)
#transport = ssh.get_transport()
#channel = transport.open_session()
stdin,stdout,stderr = ssh.exec_command(command)
print stdout.readlines()