php用到shell脚本,使用php执行shell脚本

我有一个shell脚本deploy.sh,它包含以下内容: –

echo "0 Importing the code"

eval "git pull -u origin master"

echo "1 Backing up existing data in database.."

// -- other code follows here

当我使用终端直接执行脚本时,我得到以下输出: –

0 Importing the code

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 3 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From bitbucket.org:user/repo

* branch master -> FETCH_HEAD

Updating db13xxx..6705xxx

1 Backing up existing data in database..

这是对的.但是,我编写了一个PHP脚本,我可以通过http来调用deploy.sh脚本.这个php页面的内容如下: –

$output = `./deploy.sh`;

echo '

', $output, '
';

当我通过浏览器调用这个php文件时,shell脚本实际上被调用了,我得到以下输出: –

0 Importing the code

1 Backing up existing data in database..

问题是eval“git pull -u origin master”命令没有执行,它的输出也没有显示.知道问题是什么吗?

解决方法:

这有效

$output = shell_exec('sh deploy.sh');

echo "$output";

?>

在此之前,请确保该文件具有chmod 777权限.

标签:shell-exec,php,shell

来源: https://codeday.me/bug/20190725/1535489.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值