tags:

views:

650

answers:

3

Hi,

I'm new to this forum. I have a PHP script in which I need to execute a shell script 'add_article.sh' which reads a parameter file and adds the news article contents to a search index (Lemur/Indri).

Executing the 'add_article.sh' script on its own (from the shell) works perfectly, but running it from within the php script I get this:

$blah = exec("./add_article.sh", $out, $ret_val);

echo $out . "<BR />";
echo $ret_val . "<BR />";

This produces

Array

255

It is in the correct directory and fails even with an absolute path. I use exactly the same format in another function in the same file that executes another script in the same directory and all is fine.

Any ideas?

A: 

Have you checked the execute permissions of your shell script? Apache runs as a user with very few permissions in most operating systems, so that may be the cause.

pgb
Yes, the scripts are chmod 777, so it shouldn't be a permissions issue.
gouwsmeister
UPDATE: It turned out to be a permissions issue. My scripts needed to access files in ANOTHER directory that I forgot about and apache didn't have permissions for that directory. Changing permissions for the fixed the problem. Thank you!
gouwsmeister
+1  A: 

$out is supposed to be an array. You should probably print_r() or var_dump() it to see what's coming back from the script; it may be telling you what's going wrong.

In general, there's probably some environmental dependency that isn't being satisfied when PHP is running the script. This is especially common if it's being run from inside Apache.

chaos
This is what var_dump() returns: array(0) { }
gouwsmeister
+1  A: 

Try:

$blah = exec("./add_article.sh", $out, $ret_val);

print_r($out);
echo '<br />';
echo $ret_val . "<br />";
karim79