I have code that roughly looks like this (the entire code is a bit too long to copy here):
import re
from subprocess import Popen, PIPE
goodOutput = re.compile(r'\S+: 0x[0-9a-fA-F]{8} \d \d\s+->\s+0x[0-9a-fA-F]{8}')
p = Popen(['/tmp/myexe', param], stdout=PIPE, stderr=PIPE, cwd='/tmp')
stdout, stderr = p.communicate()
ret = goodOutput.match(stdout)
if ret == None:
print "No match in: " + stdout
match() doesn't match this, but if I copy the stdout from the print statement and use that string in the above script as the value for stdout, it matches. So the regexp pattern should be all right. Also, if I read the string from stdin (stdout = sys.input.read()) it again works.
I've tried to rstrip() stdout as well, but that didn't help either (besides, shouldn't match() make this unnecessary?).
When I print stdout with repr() the string looks like
'xxx[a]: 0xff2eff00 4 7\t->\t0xff2eff00\n'
and if I try to match() to this it doesn't match. Is this an issue with the tab and newline characters and if so, what should I do?