php 执行命令屏幕输出捕捉,在php执行linux命令时显示所有输出

为了方便,给测试地址做了git hook,可以参考之前的文章,利用git的hook自动部署代码。现在发现使用exec之类的命令无法获取到错误的输出,获取到的结果相对于直接在终端执行命令少了很多信息,这很不方便调试。

Updating 0430ef4..377d045

在终端则是

Updating 0430ef4..377d045

error: Your local changes to the following files would be overwritten by merge:

public/coding.php

Please, commit your changes or stash them before you can merge.

Aborting

下面这么多的错误信息都没了,没办法知道是因为什么卡住,开始以为PHP函数原因,后来google了一下,才发现是需要更改一下shell的错误输出重定向,使用如下即可

cd /home/wwwroot/*** && /usr/bin/git pull 2>&1

修改之后获取到的错误信息如下

error: Your local changes to the following files would be overwritten by merge: public/coding.php

Please, commit your changes or stash them before you can merge.

Aborting

Updating 0430ef4..fac8fed

正确的如下

From https://git.coding.net/****/****

4454adb..40ba1aa develop -> origin/develop

Updating 4454adb..40ba1aa

Fast-forward

readme.md | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)

这样就很直观了

分享本文到:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值