views:

121

answers:

1

shell_exec():

I'm doing a PHP site that uses a shell_exec() function like this:

$file = "upload/" . $_FILES["file"]["name"];

$output = shell_exec("leaf $file");
echo "<pre>$output</pre>";

Where leaf is a program that is located in the same directory of my script, but when I tried to run this script on the server, I just got nothing.


exec():

If I try by using exec() like this:

exec("sh " . getcwd() . "leaf -h", &$output);
echo "<pre>";
print_r(&$output);
echo "</pre>";

I got this:

Array
(
)

If I do the same thing, but using echo instead of print_r, I got only this: Array

What I can do?

+1  A: 

Have you tried to use the full path with your "leaf" reference?

$output = shell_exec("/var/local/leaf $file");
gurun8
Yeah, I've already done this: `$output = shell_exec("sh " . getcwd() . "/leaf $file");`, but I got nothing too.
Nathan Campos
Can you try just using a static path and see if that changes anything? getcwd() would most likely get the CWD from Apache which is probably different than what you're thinking. You might also consult the error_log for clues.
gurun8
I've put the static path and I still got nothing.
Nathan Campos
Do you think that this is an issue of the "leaf" command not being executed or the output not being captured? Maybe there's an issue with this "leaf" command an the output from it? It's hard to speculate with any certainty in generalities but I feel your pain.
gurun8
I've tried `ls` and it worked, but any other programs that I try that aren't on the `PATH` I get nothing.
Nathan Campos
Even if I add the directory to the `PATH`, I still got nothing. **:'(**
Nathan Campos
The only other place I'd look would be the error_log. If there's nothing there, then it would suggest to me a server configuration issue and that could really be like searching for a needle in a haystack.Have you searched the web and other sources for a PHP equivalent library for whatever script this "leaf" command purports too?
gurun8