From: m on 1 Jul 2010 00:12 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? And, can I safely strip sets of 5 characters from the front as long as they start with Escape (27)? Thanks, Mark.
From: Chris Rebert on 1 Jul 2010 00:27 On Wed, Jun 30, 2010 at 9:12 PM, m <mtigges(a)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
From: Nobody on 1 Jul 2010 03:42 On Wed, 30 Jun 2010 21:12:12 -0700, m wrote: > 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. <ESC>[00m is the ANSI code to reset attributes to their default state. <ESC>[37m is the ANSI code to set the foreground color to white. > Can anyone enlighten me as to what is going on? > > And, can I safely strip sets of 5 characters from the front as long as > they start with Escape (27)? No, escape sequences can be of arbitrary length. The first thing to try is: del os.environ['TERM'] Any correctly-written program uses the value of the TERM environment variable to select escape codes which are appropriate for the terminal being used. Unfortunately, there are many incorrectly written programs which assume that all terminals support certain escape sequences. The fact that the program is using escape sequences even when stdout/stderr isn't a tty indicates that it isn't correctly written, so it far from certain that clearing TERM will work.
From: m on 5 Jul 2010 18:01 On Jul 1, 12:42 am, Nobody <nob...(a)nowhere.com> wrote: > On Wed, 30 Jun 2010 21:12:12 -0700, m wrote: > > 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. > > <ESC>[00m is the ANSI code to reset attributes to their default state. > <ESC>[37m is the ANSI code to set the foreground color to white. > > > Can anyone enlighten me as to what is going on? > > > And, can I safely strip sets of 5 characters from the front as long as > > they start with Escape (27)? > > No, escape sequences can be of arbitrary length. > It turned out that make was aliased to colourmake, and the escape codes were being put in there for beautifying the console output. Sorry to bother everyone.
|
Pages: 1 Prev: Composition of functions Next: Reversing backslashed escape sequences |