Shell Apache 中的 Exec 将输出发送到错误日志
Shell Exec in Apache sends output to error log
我需要 运行 来自 Apache 网络服务器中 运行 脚本的 php 脚本。我已经尝试了 exec 和 shell_exec 并且两次脚本 运行 都很好但是输出进入了错误日志(就像在做 error_log($output)).
所以我的问题是如何捕获变量中的输出而不是将其发送到错误日志?
因为shell_exec
不抢stderr
,只抢stdout
。
您必须在命令末尾添加 2>&1
以将 stderr
传输到 stdout
,然后两者都将出现在 return 字符串中 shell_exec
.
如果要分别捕获文件描述符stderr
和stdout
,可以使用proc_open
instead.
我需要 运行 来自 Apache 网络服务器中 运行 脚本的 php 脚本。我已经尝试了 exec 和 shell_exec 并且两次脚本 运行 都很好但是输出进入了错误日志(就像在做 error_log($output)).
所以我的问题是如何捕获变量中的输出而不是将其发送到错误日志?
因为shell_exec
不抢stderr
,只抢stdout
。
您必须在命令末尾添加 2>&1
以将 stderr
传输到 stdout
,然后两者都将出现在 return 字符串中 shell_exec
.
如果要分别捕获文件描述符stderr
和stdout
,可以使用proc_open
instead.