Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98888
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2015-11-16 05:43 -0800 |
| Message-ID | <6b2adb7a-7f2f-48ba-afa7-28e597bb9948@googlegroups.com> (permalink) |
| Subject | pexpect matching? |
| From | Didymus <lynto28@gmail.com> |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
pexpect matching? Didymus <lynto28@gmail.com> - 2015-11-16 05:43 -0800
csiph-web