“before”方法在Pexpect

时间:2016-02-03 15:11:18

标签: python telnet pexpect

简短场景:我使用Python和Pexpect库发送telnet命令。

我遇到了“child.before”行为,我无法改变或理解。当我读取myResult=child.before的输出时,我看到了我发送的命令(使用child.sendline()),命令的结果以及最终的提示。

但是,通常发送的命令不在一行。如果命令足够长,则会引入换行符。

示例:

代码:

child.sendline('tail -f /myLocation | grep "something"')
child.expect('myPrompt',timeout=100)
myResult=child.before
print(myResult)

结果:

  • tail -f / myLocation | grep的
  • “东西”
  • 命令输出

预期结果

  • tail -f / myLocation | grep“something”
  • 命令输出

因此我不能安全地使用myResult.split('\n')方法。

任何帮助将不胜感激。 谢谢!

0 个答案:

没有答案