我正在使用Pexpect模块连接到远程服务器。我可以成功发送和检索响应。我正在尝试通过期待垃圾来清除缓冲区,并假定它将清除缓冲区,但实际上并没有清除缓冲区。
下面是我的示例代码
import pexpect
obj = pexpect.spawn("telnet 172.16.250.250", maxread=8192)
obj.sendline("")
result = obj.expect(expected, timeout=3) --> getting output here `OUTPUT 1`
obj.sendline("1")
time.sleep(3)
try:
obj.expect("Asdfgdsad", timeout=2) --> I am expecting to clear buffer here but it did not
except pexpect.TIMEOUT:
pass
print("buffer is", obj.buffer) . --> This is printing output `OUTPUT 1` as I have meniotned
我在这里做错什么了?我正在使用python3.7。如果我没记错的话,它在python2.X中正常工作