doqau82086
doqau82086
2011-06-22 22:33
浏览 159

在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?

图片转代码服务由CSDN问答提供 功能建议

我正在为用github创建一个用PHP编写的部署脚本。 我正在使用 shell_exec 命令来运行 git pull ,它运行正常。

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

  git pull origin master 
更新f706749..8468d24 
test.txt:需要更新
error:条目'test.txt'不是uptodate。 无法合并。
   
 
 

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

 更新f706749..8468d24 
test.txt:需要更新
   
 
 

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongxuan58311366668
    dongxuan58311366668 2011-06-22 22:38
    已采纳

    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.

    点赞 评论
  • doutang1856
    doutang1856 2011-06-22 22:36

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

    Try capturing stderr.

    Hope this helps and good luck!

    点赞 评论
  • dongtaotao19830418
    dongtaotao19830418 2011-06-22 22:39

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

    点赞 评论

相关推荐