在运行PHP的服务器Apache上,我有一个总是返回null的命令。
exec(存在az存储容器--帐户名$accountName--账户密钥$key——名称$containeurName"$输出(;
我修改了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,
]);