我正在嘗試制作一個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 回答
- 0 關注
- 453 瀏覽
添加回答
舉報
0/150
提交
取消