4

I'm using Python to build multiple VS solutions from a given directory using msbuild.exe. I only want specific output, but to save work, the best way to interpret the results is with the original ANSI encoding.

Example:

import os
output = os.popen("MSBuild VSTests.sln").read()
print output

This prints the output, but without color. Is there any way to preserve this?

John
  • 2,675
  • 2
  • 18
  • 19
  • 2
    Welcome to SO! i doubt that you want to preserve the escape sequences, because most likely they would make your output even more unreadable if they are using ansi-escape sequences. a better way would be to filter for content. Providing a little sample-output for us is never wrong. – Don Question Nov 08 '12 at 23:32

1 Answers1

3

You can't, as far as I know. The color is a property of the console and not of the output text itself. It's not like in Linux where you get escape characters in the text that set the color and reading that out back to console preserves color.

Another side effect of this is that you can't have a separate color for STDOUT and STDERR as shown in this SO question:

Setting stdout/stderr text color in Windows

Community
  • 1
  • 1
kichik
  • 33,220
  • 7
  • 94
  • 114