我想在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";
}
执行后密码提示依然存在,如何避免呢?