why no color output with Python?
I have a batch file which calls .Net solution to build the project. On the dos console window, the warning and error will be in different color, green and red开发者_Python百科, looks nice. When the batch file called from Python, no color at all, all in a single color. Is it possible to get the same colorful result with python? my call to the batch file is like this:
p = subprocess.Popen('manualBuild.bat', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
print line,
retval = p.wait()
thanks
Some programs test to see if they're actually connected to a console/terminal, and suppress attribute changes if they're not in order to make it easier to parse/process the output. I know that on *nix systems you can use unbuffer
to fool the program, but I don't know if there's a Windows equivalent.
If this were UNIX, I'd suggest you don't get the output in a variable but just let the program print it out (ie. don't pass stdout
to subprocess). Maybe you can try that once?
精彩评论