我尝试执行一个嗅探串行端口并在标准输出上打印的命令。该命令连续运行,它不会退出或停止。当我使用 putty SSH 控制台时,我可以在控制台上看到不断更新的数据。
我能够发送命令并开始跟踪。当我尝试使用 Paramiko 通道读取输出数据时,使用该recv
函数读取。我观察到它没有捕获嗅探器发出的所有数据。
recv
我在检查recv_ready
状态后执行操作。
下面是代码。如何避免丢失数据?
ssh= paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.connect('host.example.com')
channel = ssh.get_transport().open_session()
channel.get_pty()
channel.exec_command("sniff /dev/stty2")
while(True):
if(channel.recv_ready): # Doesnt get triggered often
print channel.recv(2048) # Reads only a part of the data