简体   繁体   English

如何使用 shell_exec 执行 aws cli 命令?

[英]How to execute aws cli commands with shell_exec?

Trying to execute aws cli commands with php shell_exec on local server (for tests).尝试在本地服务器上使用 php shell_exec执行 aws cli 命令(用于测试)。 I'm using xampp, windows operating system, Laravel and php, I installed aws cli on windows.我正在使用 xampp、windows 操作系统、Laravel 和 php,我在 windows 上安装了 aws cli。

Windows cmd recognizes the aws commands, but when I try to execute the aws command with shell_exec i get an error: "aws is not recognized as an internal or external command" . Windows cmd 识别 aws 命令,但是当我尝试使用shell_exec执行 aws 命令时,出现错误: “aws 未被识别为内部或外部命令”

Tried this simple script:尝试了这个简单的脚本:

$exec = shell_exec('aws --version');

$exec return null.

Appreciate any help.感谢任何帮助。

if you can't run the command directly in shell_exec(), then what you can do is make a batch file with the command and place it on the root of your website.如果您不能直接在 shell_exec() 中运行该命令,那么您可以做的是使用该命令制作一个批处理文件并将其放在您网站的根目录中。 Then, just run:然后,只需运行:

<?php echo exec("script.bat"); ?>

also, make sure to put any environment variables needed and recommend to use full path for the aws executable另外,请确保放置所需的任何环境变量,并建议使用 aws 可执行文件的完整路径

I solved it.我解决了。 It was pretty simple.这很简单。 It doesn't enough to restart xampp.重新启动 xampp 是不够的。 I also had to quit xampp and re enter我也不得不退出 xampp 并重新进入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM