tags:

views:

13

answers:

0

Hi all,

I am trying to colorize my output (from a scons based system). I am using the following code snippet:

default_colors = self.get_text_attr()
    default_bg = default_colors & 0x0070
    stdout_handle = -1
    stdout_handle = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
    retval = SetConsoleTextAttribute(self.stdout_handle, FOREGROUND_BLUE | default_bg | FOREGROUND_INTENSITY)
    sys.__stdout__.write('Tester ['+str(self.stdout_handle)+']: '+text)
    if retval == 0:
       raise WinError()
    sys.__stdout__.flush();
    #self.stdout.write('Tester : '+text)
    self.set_text_attr(default_colors)

This code snippet was taken from Burgaud's site and overrides the default sys.stdout implementation. The text gets printed with the Tester tag, however, I don't see the color formatting. I get a invalid handle error when I try SetConsoleTextAttribute. But the GetStdHandle seems to return a valid handle (96 in my case). Could it be that this is being called from a child process that is redirecting its output via subprocess.PIPE?

Any pointers?

thanks