在PHP中使用shell_exec运行'git pull'不显示错误

ada*_*tle 1 php git shell-exec

我正在用PHP编写的github创建部署脚本.我正在使用shell_exec命令运行git pull哪个工作正常.

拉出错误时会出现问题.如果我在终端中执行此操作,则会收到完整错误.例如:

git pull origin master
Updating f706749..8468d24
test.txt: needs update
error: Entry 'test.txt' not uptodate. Cannot merge.
Run Code Online (Sandbox Code Playgroud)

但是当我在shell_exec输出中运行相同的命令被截断为just

Updating f706749..8468d24
test.txt: needs update
Run Code Online (Sandbox Code Playgroud)

错误消息正在被切断,可能是因为它是来自先前响应的响应.有没有办法返回完整的输出?

Pet*_*ans 7

10-1缺少的行不是写入stdout而是写入stderr.

在这种情况下,你可以重定向标准错误标准输出

"command    2>&1"
Run Code Online (Sandbox Code Playgroud)

2>&1重定向错误消息到正常输出文件.