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?

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

1 Comment

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?
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.