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, 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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.