亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在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 關注
  • 453 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號