从php脚本执行colorized命令 [英] Execute a colorized command from a php script

查看:157
本文介绍了从php脚本执行colorized命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个命令,例如'git diff',当我从终端运行时输出彩色化的结果。

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

现在,我想调用该命令从CLI php脚本并在控制台中显示彩色化的结果。我尝试用exec(),system(),passthru(),但在所有情况下,输出已经转换为纯黑色和白色文本。

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?

推荐答案

很可能你正在运行的命令是检查输出是否是终端, 't。通常有一种方法来强制它,但这将是特定于命令本身;在 git diff 的情况下,您可以指定 - color = always

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.

这篇关于从php脚本执行colorized命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆