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

I'm creating a deployment script for github, written in PHP. I'm using the shell_execcommand to run git pull which works fine.

My issue occurs when there is an error with the pull. If I do it in Terminal, I get the full error. For example:

git pull origin master
Updating f706749..8468d24
test.txt: needs update
error: Entry 'test.txt' not uptodate. Cannot merge.

But when I run the same command in shell_exec the output is truncated to just

Updating f706749..8468d24
test.txt: needs update

The error message is getting cut off, possibly because it's a response from the previous response. Is there a way to return the full output?

10-1 the missing lines are not written to stdout but to stderr.

In that case you can redirect the stderr to stdout with

"command    2>&1"

The 2>&1 redirects the error messages to the normal output file.

By searching a bit, I might have found the answer to your problem.

Try capturing stderr.

Hope this helps and good luck!

Pipe the error to your output. In the exec command use 2> which is the "standard error" stream.