Forum Moderators: coopster

Message Too Old, No Replies

exec() failing with exit code 6

         

burnin240sx

9:05 pm on Nov 4, 2010 (gmt 0)

10+ Year Member



I have this little peice of code that fails to run under PHP but runs fine a a user.
exec("/var/www/SNS/PLANETS/Programs/Planet_Positions.exe",$out,$return);

//echo output.
echo "exit code = " . $return;
echo "<br/>$ out =" . $out . "<br/>";
//show output

echo "$ out = ";
print_r($out);
echo "<br/>Array $ out output = <br/>";
foreach ($out as $val)
{
echo htmlentities($val) . "<br/>";
}

Here is the output
exit code = 6
$ out =Array
$ out = Array ( [0] => [1] => [2] => PLANETARY POSITION PROGRAM )
Array $ out output =


PLANETARY POSITION PROGRAM

note that array 2 is only the first line of output.
Is exec not allowed to execute programs below web root? ie /var/www/

lammert

10:22 pm on Nov 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi burnin240sx, first of all Welcome to WebmasterWorld!

It doesn't seem that execution permissions are the problem, because the first output line of the executable is returned in the $out array.

The error code 6 is generated by the Planet_Positions.exe executable. The documentation of that program may give a clue about the source of the error. One possible cause may be that the program is expecting the calling process to be in a specific directory with configuration or other data. Another problem can be that the PHP process is running as a user or group which doesn't have enough privileges to fully use the external executable or open needed data files.

burnin240sx

12:59 pm on Nov 5, 2010 (gmt 0)

10+ Year Member



Here is the weird thing. I changed the passwd file so apache has a bash shell and I can run the program fine that way as well.
I do get this weird output when i ran it from within php -a

system("/var/www/SNS/PLANETS/Programs/Planet_Positions.exe");
open: No such file or directory
apparent state: unit 4 named ../Files1/Input.dat
lately writing sequential formatted external IO

Very weird. We are going to play around with the prgram. It was made by the person I'm helping with this code. So that should make debugging a littler easier.

A little history.
This program was a folder under the apache root (i.e. /var/www/html/) and it worked flawlessly. but when we moved it to (/var/www/Programs/) and now we get this weird error.

burnin240sx

3:24 pm on Nov 5, 2010 (gmt 0)

10+ Year Member



weird update. the program will run fine if all the files needed including the exectable are in the same folder as the .php file.

So the question is....
Is it a problem to run a file that is not in the same folder as the PHP file calling it?