使用php的popen保留彩色输出 [英] Preserve colored output using php's popen

查看:90
本文介绍了使用php的popen保留彩色输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在php中使用popen时,是否可以保留程序可能生成的彩色输出?也许我可以告诉外壳打印所有颜色转义序列,而不是解决它们的方法吗?

When using popen in php, is there a way to preserve the colored output a program might generate? Is there maybe a way I can tell the shell to print all color escape sequences, instead of resolving them?

推荐答案

这取决于您正在调用的程序.通常,如果程序支持彩色输出,则会询问操作系统我在终端上运行吗?".如果是,则输出颜色代码.如果没有,它不会.如果通过popen()运行该程序,则操作系统会说不,您不在终端上运行",并且该程序将选择不输出颜色代码(因为它们会在捕获的输出中造成混淆).

That depends on the program you are calling. Usually, if a program supports coloured output, it would ask the OS, "am I running on a terminal?" If yes, then it outputs colour codes. If not, it won't. If you run that program through popen(), then the OS would say "no, you're not running on a terminal" and the program would choose not to output the colour codes (because they would be confusing in the captured output).

即使没有将输出写入终端,某些程序也可以选择强制输出颜色代码.但是,如果程序尚无办法,则不能在外部强制这样做.

Some programs may have an option to force the output of colour codes even if output is not being written to a terminal. However, that is not something you can force externally if the program doesn't already have a way to do it.

这篇关于使用php的popen保留彩色输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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