我想用PHP exec()在Windows机器上远程执行tracert。我有:
<?php
echo exec("C:\\Windows\\System32\\TRACERT.exe");
echo "<br/>Success!";
?>这不会给我带来错误,它会打印出“成功!”但是如何将参数(例如IP地址)传递给tracert.exe并在变量或数组中打印结果?我不知道要传递一个类似于: tracert等参数的语法。
发布于 2014-02-22 10:40:50
我更喜欢passthru(),因为traceroute输出可以在浏览器中动态监视,而不必等到完成。
$IP=$_REQUEST['IP'];
set_time_limit(120);
echo "<h1>Traceroute $IP</h1><pre>";
passthru("tracert.exe -h 8 $IP");发布于 2014-02-21 23:12:58
默认情况下,exec只返回执行命令的最后一行。
您应该按以下方式使用shell_exec:
<?php
$result = shell_exec("C:\\Windows\\System32\\TRACERT.exe www.google.com");
print $result;
echo "<br/>Success!";
?>https://stackoverflow.com/questions/21946979
复制相似问题