为了账号安全,请及时绑定邮箱和手机立即绑定

在python中丢失stdout数据

在python中丢失stdout数据

沧海一幻觉 2021-04-12 14:26:16
我正在尝试制作一个python脚本,它将通过ssh在远程计算机上运行bash脚本,然后解析其输出。bash脚本在stdout中输出大量数据(例如5兆字节文本/ 5万行),这是一个问题-我只能在大约10%的情况下获得所有数据。在其他90%的情况下,我得到的期望值约为97%,并且看起来总是在最后修剪。这是我的脚本的样子:import subprocessimport reimport sysimport paramikodef run_ssh_command(ip, port, username, password, command):    ssh = paramiko.SSHClient()        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())                                                       ssh.connect(ip, port, username, password)                                                                       stdin, stdout, stderr = ssh.exec_command(command)                                                               output = ''                                                                                                     while not stdout.channel.exit_status_ready():                                                                       solo_line = ''                                                                                                  # Print stdout data when available                                                                              if stdout.channel.recv_ready():                                                                                     # Retrieve the first 1024 bytes                                                                                 solo_line = stdout.channel.recv(2048).                                                                          output += solo_line                                                                                     ssh.close()                                                                                                     return output                                                                                                                                                   我很确定问题出在某些内部缓冲区的溢出中,但是哪一个以及如何解决呢?
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 387 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信