【问题标题】:pexpect Prompt with new linepexpect 提示换行
【发布时间】:2017-02-20 00:30:52
【问题描述】:

我正在使用 pexpect 在 CentOS 上自动配置应用程序。我的提示是换行如下,

Please enter command below.

在下一行(空白/新行),我需要输入必要的命令,

我尝试了几件事来匹配 r'\b below.\b' 以检查新行 r'\r\n(\w+)' 、空格 (\s) 等等,但没有一个与 expect 提示符匹配。

例如。

child.sendline('a')
child.expect([pexpect.TIMEOUT,r'\b below.\b'])
print child.before

如果有人可以为此提供任何建议,那将是很大的帮助..

【问题讨论】:

  • 试试r'.*\b below\.\b'expect
  • .expect(r'Please enter command below\.\r\n')
  • pexpect 读取流并且无法检查字符的序列,您必须使用expect

标签: regex python-2.7 pexpect


【解决方案1】:

(我知道这是旧的,但它可能对某人有所帮助)

这适用于我的 pxssh,它基本上是一个包装器:

expect_string = 'below.'
child.expect(expect_string)
child.sendline('a')
print(child.before)

如果我没看错你的代码,那么你的 sendline 就在你预料之外。你需要切换它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 2018-10-01
    • 2016-08-15
    • 2013-05-12
    • 2016-08-11
    • 1970-01-01
    • 2013-02-23
    相关资源
    最近更新 更多