php-命令不能与php shell_exec一起使用

时间:2021-04-03 17:33:06

I want to execute following command on my Ubuntu server using php:

我想使用php在我的Ubuntu服务器上执行以下命令:

android create project --target 8 --name $fname --path ./$fname --activity MainActivity --package $fpack 2>&1

The above command is to create an Android app project. So when I enter this command on my terminal then it works fine, but when I execute it via php:

上面的命令是创建一个Android应用程序项目。所以当我在我的终端上输入这个命令然后它工作正常,但是当我通过php执行它时:

<?php
$fname = $_POST['fname'];
$fpack = $_POST['fpack'];
$email = $_POST['email'];

//Creating a new Android project
var_dump(shell_exec("android create project --target 8 --name $fname --path ./$fname --activity MainActivity --package $fpack 2>&1"));

?>

When I run my PHP script I get the following output:

当我运行我的PHP脚本时,我得到以下输出:

string(26) "sh: 1: android: not found "

Why it works when I enter manually in terminal (from user 'ashish' account) but not with php? my apache user and group is same (ashish). Any help will be appreciated :)

为什么当我手动输入终端(来自用户'ashish'帐户)但不能用php输入时?我的apache用户和组是相同的(ashish)。任何帮助将不胜感激 :)

1 个解决方案

#1


0  

see this

http://php.net/manual/en/function.shell-exec.php

http://php.net/manual/en/function.exec.php

shell_exec — Execute command via shell and return the complete output as a string

shell_exec - 通过shell执行命令并将完整输出作为字符串返回

exec — Execute an external program

exec - 执行外部程序

so try to use exec() insted shell_exec()

所以尝试使用exec()insted shell_exec()

exec("android create project --target 8 --name $fname --path ./$fname --activity MainActivity --package $fpack 2>&1")

exec(“android create project --target 8 --name $ fname --path ./$fname --activity MainActivity --package $ fpack 2>&1”)

#1


0  

see this

http://php.net/manual/en/function.shell-exec.php

http://php.net/manual/en/function.exec.php

shell_exec — Execute command via shell and return the complete output as a string

shell_exec - 通过shell执行命令并将完整输出作为字符串返回

exec — Execute an external program

exec - 执行外部程序

so try to use exec() insted shell_exec()

所以尝试使用exec()insted shell_exec()

exec("android create project --target 8 --name $fname --path ./$fname --activity MainActivity --package $fpack 2>&1")

exec(“android create project --target 8 --name $ fname --path ./$fname --activity MainActivity --package $ fpack 2>&1”)