简体   繁体   English

Pexpect无法正确获取输出

[英]Pexpect does not get the output correctly

I'm using Pexpect to interact with a remote firewall. 我正在使用Pexpect与远程防火墙进行交互。 Everything in the interaction is okay but, when I try to get the output with child.before, I do not get what I want. 交互中的所有内容都可以,但是,当我尝试使用child.before获得输出时,我没有得到想要的东西。 This is my code: 这是我的代码:

child = pexpect.spawn('ssh admin@X.X.X.X')
child.sendline(password)
child.expect('>')
child.sendline('set cli pager off')
child.expect('>')
child.send('show system info')
child.expect('>')
child.before

The output I get in child.before sentence is next: 我在child.before句子中得到的输出是下一个:

' set cli \\r\\x1b[Kadmin@name(active)' '设置cli \\ r \\ x1b [Kadmin @ name(active)'

In the firewall side, this is the interaction I'm receiving (It is copied directly from child.interact()): 在防火墙方面,这是我正在接收的交互(直接从child.interact()复制):

admin@ctsmefw1(active)> set cli pager off
admin@ctsmefw1(active)> show system info

hostname: name
ip-address: ip
# ...There are more lines but these are omitted here...

admin@name(active)> 

So the interaction with the firewall is correct. 因此与防火墙的交互是正确的。 Why I can'nt get the output? 为什么我无法获得输出? What am I doing wrong? 我究竟做错了什么?

Thanks for your help, regards 感谢您的帮助,问候

Mike 麦克风

您应该将child.send('show system info')更改为child.sendline('show system info')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM