0
我嘗試ping www.google.de
與shell_exec
並將結果存儲到一個變量中,但我從shell_exec
得不到結果。sudo_exec什麼也沒有返回
<?php
$ping = 'sudo ping -c 4 ';
$url = 'www.google.de';
$command = $ping . $url;
$ping_result = shell_exec($command);
$datei = fopen("/var/www/myProject/result_ping","w") or die ("Could not open file!");
sleep(10);
if ($datei == false)
{
$ping_result = "Cannot open file!";
}
else
{
fwrite ($datei , $ping_result);
fclose ($datei);
}
echo $command; //Output: sudo ping -c 4 www.google.de
echo $ping_result; //Output: nothing
?>
文件result_ping
擁有所有權利(chmod 777)。 也許網絡服務器不允許執行ping
?
非常感謝!現在我得到了:'sudo:沒有tty禮物,沒有askpass程序指定'輸出'ping_result'我會做我的研究。 – Black