Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98888

pexpect matching?

X-Received by 10.129.80.66 with SMTP id e63mr22856636ywb.51.1447681424711; Mon, 16 Nov 2015 05:43:44 -0800 (PST)
X-Received by 10.50.98.67 with SMTP id eg3mr49944igb.1.1447681424681; Mon, 16 Nov 2015 05:43:44 -0800 (PST)
Path csiph.com!au2pb.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!i2no3671581igv.0!news-out.google.com!l1ni6267igd.0!nntp.google.com!i2no3947147igv.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Mon, 16 Nov 2015 05:43:44 -0800 (PST)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=192.148.197.11; posting-account=4cYVCwoAAAB57uJAneV0jkV1MFz4aQe5
NNTP-Posting-Host 192.148.197.11
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <6b2adb7a-7f2f-48ba-afa7-28e597bb9948@googlegroups.com> (permalink)
Subject pexpect matching?
From Didymus <lynto28@gmail.com>
Injection-Date Mon, 16 Nov 2015 13:43:44 +0000
Content-Type text/plain; charset=ISO-8859-1
X-Received-Bytes 1937
X-Received-Body-CRC 319345755
Xref csiph.com comp.lang.python:98888

Show key headers only | View raw


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


Thread

pexpect matching? Didymus <lynto28@gmail.com> - 2015-11-16 05:43 -0800

csiph-web