Friday, July 27, 2018

Use regex for pexpect()

I was writing a pexpect script to wait for (qemu).

child.pexpect('(qemu)')

didn't work.

ree = re.compile('\(qemu\)')
child.pexpect(ree)

worked.

In fact,

child.expect('\(qemu\)')

this just worked.

Strings will be compiled to re types
https://pexpect.readthedocs.io/en/stable/api/pexpect.html

expect_exact() would not compile strings to re types.

No comments:

Post a Comment