php - 将 PHP 通知和警告从 STDOUT 重定向到 STDERR

标签 php bash stdout stderr io-redirection

是否有标志或命令可用于在命令行上运行的单个命令中将所有 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/

相关文章:

php float 错误

linux - 通过网络优化 SCP

linux - 通过符号链接(symbolic link)调用时如何在脚本本身内部获取脚本文件路径

Python子进程;无法读取标准输出

python - 如何在 Windows 中重定向 Python 中的 C 级流?

php - 如何在 SPhinxql 查询生成器中设置匹配模式

php - 如果存在数据,如何执行更新查询,否则将数据插入 Mysql?

php - 在 Bootstrap 模态 (Laravel) 中对按钮执行特定操作

bash - 在 Unix 中将文件中的行从行号 `n1` 移动到行号 `n2`

Ruby 断管 @io_write - <STDOUT>