简短场景:我使用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)
结果:
预期结果
因此我不能安全地使用myResult.split('\n')
方法。
任何帮助将不胜感激。 谢谢!