Maxim Lanin
Maxim Lanin

Reputation: 4531

Make console calls in php and read output with colors

In my php code I want to make console calls (e.g. 'git diff') via exec(), or proc* functions.

Is there any method to capture their output with colors?


Found a method: https://stackoverflow.com/a/35011507/2450729

Upvotes: 0

Views: 373

Answers (3)

Alex Blex
Alex Blex

Reputation: 37038

You can ask git to always color output:

git -c color.diff=always diff

Upvotes: 1

lwb
lwb

Reputation: 389

If you're using linux, you can use the tput setat command to highlight the output. Look this: http://linuxcommand.org/lc3_adv_tput.php

Upvotes: 0

Maxim Lanin
Maxim Lanin

Reputation: 4531

Found the way to do it.

There is no method to do it straight through php. But you can capture colorized output by wrapping your command with script -c <command> tool. It will save colors.

Upvotes: 1

Related Questions