以下是下面列出的计划。我试图从PHP运行shell命令,所以我写了以下代码:
<?php
$argument1 = $argv[1];
$output = shell_exec('sudo whois ');
echo "<pre>$output</pre>";
?>
但每次执行命令时都会执行但不显示输出。仅显示选项。
我在shell中的命令是
php filename.php google.com
答案 0 :(得分:2)
您没有在命令中使用传递参数。您需要在whois
命令中使用参数:
<?php
$argument1 = escapeshellarg($argv[1]);
$output = shell_exec('whois '. $argument1);
echo "<pre>$output</pre>";
?>
PS:whois
也可以在没有sudo
的情况下进行调整。