python中的Restrict或limit read_very_eager()

python中的Restrict或limit read_very_eager(),python,telnetlib,Python,Telnetlib,我正在一台远程机器上执行一些命令,该机器使用telnet lib通过telnet会话运行linux。当我提出以下意见时: tn.write("<binary_name>") time.sleep(10) tn.write("cat <path_of_output_file>") rd_buf=tn.read_very_eager() print(rd_buf) tn.write(“”) 时间。睡眠(10) tn.write(“cat”) 读得非常急切 打印(rd_buf

我正在一台远程机器上执行一些命令,该机器使用telnet lib通过telnet会话运行linux。当我提出以下意见时:

tn.write("<binary_name>")
time.sleep(10)
tn.write("cat <path_of_output_file>")
rd_buf=tn.read_very_eager()
print(rd_buf)
tn.write(“”)
时间。睡眠(10)
tn.write(“cat”)
读得非常急切
打印(rd_buf)

它给出二进制文件的输出和
cat
命令的输出。而我只需要
cat
命令的输出。我只在
read\u very\u-eager
read\u工作过,直到
。如何将缓冲区变量限制为仅保存
cat
命令的内容?

在对
read\u until()
read\u very\u eager()
进行了一番尝试后,我终于解决了这个问题。我所要做的就是:

tn.write("<binary_name>")
time.sleep(10)
junk=tn.read_very_eager()
tn.write("cat <path_of_output_file>")
rd_buf=tn.read_very_eager()
print(rd_buf)
tn.write(“”)
时间。睡眠(10)
垃圾,垃圾
tn.write(“cat”)
读得非常急切
打印(rd_buf)
加上一行(
junk=tn.read\u very\u eager()
),我就能实现我想要的。引用python官方文档:

Telnet.read_very_eager()

在I/O(渴望)中读取可以不阻塞的所有内容

我从中得到了一个暗示,并使剧本有力地停止了“阅读”。然后重新开始阅读,这达到了目的