[英]php exec command with azure cli always return null
在運行 PHP 的服務器 Apache 上,我有一個總是返回 null 的命令。
exec("az 存儲容器存在 --account-name $accountName --account-key $key --name $containeurName", $output);
我修改了 sudoers 文件,但它沒有改變任何東西:
www-data ALL=(ALL) NOPASSWD: /usr/bin/az
謝謝你的幫助。
使用exec($your_command, $output, $error_code)
並查看$error_code
包含的內容。 可能只是因為az
不在 PHP 的 PATH env 變量中。
嘗試將完整路徑放入可執行文件,通常是這樣的:
<?php
// A default path in case "which az" doesn't work.
define('AZ_DEFAULT_PATH', '/usr/bin/az');
// Find the path to az with the "which" command.
$az_path = exec('which az');
if ($az_path === false) {
$az_path = AZ_DEFAULT_PATH;
}
// Sanitize your variables to avoid shell injection and build the command.
$cmd = $az_path .
"storage container exists --account-name $accountName " .
"--account-key $key --name $containeurName";
$last_line = exec($cmd, $full_output, $error_code);
// Then check if $last_line !== false and check $error_code to see
// what happened.
var_export([
'$cmd' => $cmd,
'$last_line' => $last_line,
'$full_output' => $full_output,
'$error_code' => $error_code,
]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.