pexpect 期待不止一种模式

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')

我在这里要做的是:

根据 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. Strings will be compiled to re types. This returns the index into the pattern list. If the pattern was not a list this returns index 0 on a successful match.
[...]