1
我想執行命令sudo ls -l
而沒有密碼提示。避免密碼提示
$streams = array(
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
2 => array("pipe", "w") // stderr
);
$process = proc_open('sudo ls -l', $streams, $pipes);
if (is_resource($process)) {
list($stdin, $stdout) = $pipes;
fwrite($stdin, "password\n"); //must write password, but not
fclose($stdin);
var_dump(stream_get_contents($stdout));
fclose($stdout);
$returnCode = proc_close($process);
echo "Return code $returnCode\n";
}
執行後密碼提示仍然存在,如何避免它?
的可能的複製http://stackoverflow.com/questions/3166123/how-to-call-shell-script-from-php-that-requires-sudo –
不幸的是沒有,須藤就是例子,我需要連接到需要密碼的工具 – cetver