Very odd output from subprocess
Chris Rebert
clp2 at rebertia.com
Thu Jul 1 00:27:41 EDT 2010
On Wed, Jun 30, 2010 at 9:12 PM, m <mtigges at gmail.com> wrote:
> I have this function:
>
>
> def GetMakeOutput(make, rules, out=None):
> p = subprocess.Popen('%s %s' % (make,rules),
> shell=True,
> bufsize=1024,
> stderr=subprocess.PIPE,
> stdout=subprocess.PIPE,
> close_fds=False)
> ret = []
> line = p.stdout.readline()
> while len(line):
> if line[:5] not in ['make[','make:']:
> if out:
> out.write(line)
> out.flush()
> else:
> ret.append(line)
> line = p.stdout.readline()
> return string.join(map(string.strip,ret),'\n')
>
> Very simple ... it cleans any line that is output from make itself.
>
> Now, I have used it for quite awhile with no problem. But, I noticed
> today that it wasn't doing its job on my 64 bit machine.
>
> If I add the line:
> for l in line: print ord(l),'\t',l
> after the first readline, I get the following:
>
>
> 27
> 91 [
> 48 0
> 48 0
> 109 m
> 27
> 91 [
> 51 3
> 55 7
> 109 m
>
> before the codes begin for the string as it appears if I just print
> it. So, what is this sequence? They seem like some sort of escape
> codes, I've never seen this before at all.
>
> Can anyone enlighten me as to what is going on?
http://en.wikipedia.org/wiki/ANSI_escape_code
Running make directly, rather than through the shell, might disable
the use of the codes in whatever program is outputting them.
It's worth a try.
Cheers,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list