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

时间:2011-06-22 22:33:49

标签: 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.

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

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

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

3 个答案:

答案 0 :(得分:7)

10-1缺失的行不会写入 stdout ,而是写入 stderr

在这种情况下,您可以使用

stderr 重定向到标准输出
"command    2>&1"

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

答案 1 :(得分:1)

通过搜索,我可能找到了问题的answer

尝试捕获stderr。

希望这会有所帮助并祝你好运!

答案 2 :(得分:0)

将错误传递给输出。在exec命令中使用2>这是“标准错误”流。