简体   繁体   English

期望有不止一种模式

[英]pexpect to expect more than one pattern

import pexpect # importing the python-expect
child = pexpect.spawn ('telnet x.x.x.x y')
child.expect ('Hit \[Enter\] to boot immediately\, or space bar for command prompt.', 300)
child.send ('\x20')
if child.expect ('loader>' or 'OK ', 10):
   child.sendline ('boot -s')

What I am trying to do here is: 我在这里尝试做的是:

  • automating login to single user mode for a device by parsing boot sequence. 通过分析启动顺序,自动将设备登录到单用户模式。
  • Connecting to the device using a terminal server over the console port. 通过控制台端口使用终端服务器连接到设备。 $ I am using pexpect as the boot sequence is a single line output. $我正在使用pexpect,因为引导序列是单行输出。
  • pexpect work for 'loader>' or 'OK ' separately & execute the next line but not together. 分别预期“ loader>”或“ OK”的工作并执行下一行,但不能一起执行。

According to the manual : 根据手册

expect(pattern, timeout=-1, searchwindowsize=-1, async=False)

This seeks through the stream until a pattern is matched. 这将搜索流,直到匹配模式为止。 The pattern is overloaded and may take several types. 模式已重载,可能有几种类型。 The pattern can be a StringType, EOF, a compiled re, or a list of any of those types. 该模式可以是StringType,EOF,已编译的re或任何这些类型的列表。 Strings will be compiled to re types. 字符串将被编译为re类型。 This returns the index into the pattern list. 这会将索引返回到模式列表。 If the pattern was not a list this returns index 0 on a successful match. 如果模式不是列表,则在成功匹配时将返回索引0。
[...] [...]

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

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