Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a colorized command from a php script

I have a command, for example 'git diff' that output a colorized result when I run it from the terminal.

Now, I want to call that command from a CLI php script and display in the console the colorized result. I have try with exec(), system(), passthru() but in all case the output has been converted to plain black and white text.

Is there a way to preserve the color of the standard result? If not, does someone know why this information get lost?

like image 924
jeanmonod Avatar asked Apr 13 '12 20:04

jeanmonod


1 Answers

In all likelihood the command you are running is checking to see if output is to a terminal and not colorizing it if it isn't. There is usually a way to force it, but that's going to be specific to the command itself; in the case of git diff, you can specify --color=always.

like image 112
Mark Reed Avatar answered Nov 11 '22 12:11

Mark Reed