0

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?

PleaseStand
  • 31,641
  • 6
  • 68
  • 95
Orca
  • 73
  • 1
  • 8

2 Answers2

1

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
Community
  • 1
  • 1
Eric Wich
  • 1,504
  • 10
  • 8
  • Hm. When you say it doesn't work, can you include in your question what error it gives? Or does it just print an empty string? – Eric Wich Jun 01 '13 at 04:53
0

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

Orangepill
  • 24,500
  • 3
  • 42
  • 63