Reputation: 73
I have the following code:
$output = shell_exec("./Program $var1 $var2");
echo "<pre>$output</pre>";
It doesn't work but
$output = shell_exec("ls");
echo "<pre>$output</pre>";
does work.
$output = shell_exec("top");
echo "<pre>$output</pre>";
also doesn't work for example. Why?
Upvotes: 0
Views: 151
Reputation: 24645
Depending on the content of $var1 and $var2 you may need to do an escapeshellarg
call around it.
$output = shell_exec("./Program ".escapeshellarg($var1)." ".escapeshellarg($var2));
even if it doesn't work it might be a good idea. Also confirm that your Path is correct. Maybe with a file_exits('./Program');
check
Upvotes: 0
Reputation: 1544
This is most certainly a permissions issue. Make sure that the file you're trying to execute with the ./ command from your script has +x perms. Here's a previous thread about giving files executable permissions: Creating executable files in Linux.
If the file already has +x rights, it could be a permissions issue with your script running the commands. Either way, if you can run ls but not ./ and top, has to be permissions.
Edit: The link I gave, I realize has a lot of info about Perl and bash scripts. The important part is that the command to make a file executable is
chmod +x ProgramName
Upvotes: 1