Paramiko channel stucks when reading large ouput

前端 未结 6 956
星月不相逢
星月不相逢 2020-12-09 05:41

I have a code where i am executing a command on remote Linux machine and reading the output using Paramiko. The code def looks like this:

ssh = paramiko.SSHC         


        
6条回答
  •  情歌与酒
    2020-12-09 06:28

    It's easier if you use the high level representation of an open ssh session. Since you already use ssh-client to open your channel, you can just run your command from there, and avoid the extra work.

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(IPAddress, username=user['username'], password=user['password'])
    
    stdin, stdout, stderr = ssh.exec_command(cmd)
    for line in stdout.readlines():
        print line
    for line in stderr.readlines():
        print line
    

    You will need to come back and read from these files handles again if you receive additional data afterwards.

提交回复
热议问题