dongque1958
2015-05-18 21:59
浏览 82
已采纳

带有彩色输出的PHP passthru

I have a script that runs other scripts based either on a specified schedule or on demand depending on the command. This allows mundane and time consuming tasks to be managed in a central location as well as simplifying the management in general. This setup exists on two servers with a (mostly) identical setup.

One of the subscripts that is run uses PHP's passthru() function. The results are stored in a database for later viewing.

The code running passthru() is:

$result = []; passthru(/usr/local/bin/wp plugin delete ' . $plugin . ' --path=' . $path, $result);

When run from the command line in putty, the output is similar to:

Success: Deleted 'hello' plugin.

On both servers, Success: is green. However, when run on server 1 via the task, the colors are stripped out. When run on server 2, the ANSI color codes remain and are recorded as follows:

[32;1mSuccess:[0m Deleted 'hello' plugin.

I need to remove the color codes from the second result, but I can't figure out what setting in CentOS (or php.ini) to look at for this. There is something different between the two servers, but I am unable to figure out what.

PHP version: 5.6.8 CentOS version: 6.6

图片转代码服务由CSDN问答提供 功能建议

我有一个脚本可以根据指定的时间表或按需运行其他脚本,具体取决于命令。 这允许在中心位置管理平凡且耗时的任务,并且通常简化管理。 此设置存在于两个服务器上,其中(大部分)设置相同。

其中一个运行的下标使用PHP的 passthru()函数。 结果存储在数据库中供以后查看。

运行 passthru()的代码是:

$ result = []; passthru(/ usr / local / bin / wp plugin delete'。$ plugin。' - path ='。$ path,$ result); \ n

从putty命令行运行时,输出类似于:

成功:删除'hello'插件。 \ n

在两台服务器上, Success:为绿色。 但是,当通过任务在服务器1上运行时,颜色会被剥离。 在服务器2上运行时,ANSI颜色代码保留并记录如下:

[32; 1mSuccess:[0m Deleted'hello'插件。

我需要从第二个结果中删除颜色代码,但我无法弄清楚CentOS(或php.ini)中的设置。 两台服务器之间有一些不同,但我无法弄清楚是什么。

PHP版本:5.6.8 CentOS版本:6.6

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongliuliu0385 2015-05-18 22:41
    最佳回答

    As we figured out in comments the problem lays in the config file of wp-cli. Change color:true to color:auto on the second server.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题