Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you have subprocesss.Popen retain color in stdout/stderr?

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?

like image 960
MrDuk Avatar asked Jun 28 '16 19:06

MrDuk


1 Answers

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.

like image 162
Roland Smith Avatar answered Sep 30 '22 20:09

Roland Smith