Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从php中的exec或shell_exec执行aws cli命令_Php_Linux_Amazon Web Services_Ubuntu_Aws Cli - Fatal编程技术网

无法从php中的exec或shell_exec执行aws cli命令

无法从php中的exec或shell_exec执行aws cli命令,php,linux,amazon-web-services,ubuntu,aws-cli,Php,Linux,Amazon Web Services,Ubuntu,Aws Cli,我在本地Ubuntu 18.04开发机器上安装了aws cli。它在终端上工作正常,例如,如果我键入: $我得到的aws是:/usr/local/bin/aws。但是,如果我尝试在php脚本中运行此命令,它将不会执行任何操作 $cmd ="aws --version"; try { $exec = exec($cmd,$output, $return); $exec2 = shell_exec($cmd); } catch(Exception $e) { echo 'M

我在本地Ubuntu 18.04开发机器上安装了aws cli。它在终端上工作正常,例如,如果我键入:

$我得到的aws
是:
/usr/local/bin/aws
。但是,如果我尝试在php脚本中运行此命令,它将不会执行任何操作

$cmd ="aws --version";

try {
    $exec = exec($cmd,$output, $return);
    $exec2 = shell_exec($cmd);
}
catch(Exception $e)
{
    echo 'Message: ' .$e->getMessage();
}
exec2
返回null exec返回127

现在我了解到这是一个路径问题,我已经尝试将其添加到路径中,但它不起作用

我知道这可以使用PHPSDK来完成,但由于各种原因,我不能使用它


有人能解释一下如何用php在Ubuntu18.04上实现这一点吗?

我的代码一直在工作。问题是我必须在命令末尾使用2>&1将stdout重定向到stderr

 $cmd = "aws redshift restore-table-from-cluster-snapshot --cluster-identifier {$this->redshift_cluster_identifier} --snapshot-identifier {$this->snapshot_identifier} --source-database-name citnow --source-table-name {$tableName} --target-database-name citnow --new-table-name {$newTableName} 2>&1";
        $exec = exec($cmd,$output, $return);

您没有向我们显示任何错误,如果您不提供一些信息,我们将无法帮助您。你确定它什么都没用吗?这两个命令都不会显示任何输出,并且您也不会打印$exec2或$output中的任何内容。exec2为null exec返回127。看起来它一直在工作。我在命令末尾使用2>&1将stdout重定向到stderr。的可能重复,等等。