我正在为github创建一个用PHP编写的部署脚本。我正在使用shell_exec
命令来运行git pull
,它运行得很好。
当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
错误消息被切断,可能是因为它是上一个响应的响应。有没有办法返回全部输出?
10-1丢失的行不会写入stdout,而是写入stderr。
在这种情况下,您可以使用将stderr重定向到stdout
"command 2>&1"
2>&1将错误消息重定向到正常输出文件。
通过搜索,我可能已经找到了你的问题的答案。
尝试捕获stderr。
希望这能有所帮助,祝你好运!
通过管道将错误发送到您的输出。在exec命令中,使用2>,这是"标准错误"流。