user3101586
user3101586

Reputation: 25

how to pass argument in php for executing shell command?

Here is the program listed below. I am trying to run the shell command from php so I have written the following code:

<?php    
$argument1 = $argv[1];    
$output = shell_exec('sudo whois ');    
echo "<pre>$output</pre>";    
?> 

But every time I execute the command it get executed but doesn't display output. Only shows the option.

My command in shell is php filename.php google.com

Upvotes: 2

Views: 3456

Answers (1)

anubhava
anubhava

Reputation: 785058

You aren't using passed argument in your command. You need to use the argument in whois command:

<?php    
$argument1 = escapeshellarg($argv[1]);  
$output = shell_exec('whois '. $argument1);    
echo "<pre>$output</pre>";    
?>

PS: whois can tun without sudo also.

Upvotes: 1

Related Questions