是否有标志或命令可用于在命令行上运行的单个命令中将所有 PHP 通知和警告重定向到 STDERR?
我想从命令行解析一个 JSON 数组,但有时我会收到来自 STDOUT 的通知和警告,导致 JSON 解析失败。
命令看起来像这样:
rake collect
收集有关本地网站的一些信息是一项抽成任务。
最佳答案
根据 configuration manual ,您需要将 display_errors
选项设置为 stderr
以便将警告/错误输出到 STDERR。
display_errors string
This determines whether errors should be printed to the screen as part of the output or if they should be hidden from the user.
Value "stderr" sends the errors to stderr instead of stdout.
您可以通过几种方式设置此选项:
1) 全局(在 php.ini
中)
display_errors = stderr
2) 在本地脚本中使用 ini_set()
:
ini_set('display_errors', 'stderr');
3) 作为命令行参数(不修改任何文件)
php --define display_errors=stderr script.php
关于php - 将 PHP 通知和警告从 STDOUT 重定向到 STDERR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17805934/