pexpect matching?
Didymus
lynto28 at gmail.com
Mon Nov 16 08:43:44 EST 2015
Greetings,
I have the following code:
import pexpect
child = pexpect.spawn('/bin/bash')
i = child.expect_exact('bash-3.2$ ')
child.sendline("rpm -q --queryformat '%{VERSION}\\n' glibc")
i = child.expect (['2', '2.5', '2.52.5', pexpect.TIMEOUT])
print child.before
print '---'
print child.after
if i == 0:
print 'We got 2'
elif i == 1:
print 'We got 2.5'
elif i == 2:
print ' We got 7'
elif i == 3:
print 'Timed Out!'
else:
print 'What happened?'
The output of the commandline is:
% rpm -q --queryformat '%{VERSION}\n' glibc
2.5
2.5
I've tried to use "\b", "^", "$" around the return stings and even expect_exact, but end up with it printing "We got 2". It's just mathcing the first character and not the entire string.
rpm -q --queryformat '%{VERSION}\n' glibc
---
2
We got 2
What am I doing wrong here? What do I need to tell the expect line to grab the entire line back to check against?
Thanks
Tom
More information about the Python-list
mailing list