开发者

Running 'git pull' using shell_exec in PHP not displaying error

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 t开发者_运维问答he 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜