I have the following code:
p = subprocess.Popen(cmd.split(' '), env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while(True):
log.info(p.stdout.readline())
if(p.poll() is not None):
break
Which works ok, except for the fact that it removes all color issued. Is there a way to retain this?
You do not specify whan cmd
is, but some programs do not emit the escape sequences necessary for color output on a terminal when they determine that their standard output is not actually connected to a terminal.
Depending on the program you may or may not be able to override that.
With ansible
, you can set the force_color
configuration variable to 1 to force color output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With