Page 1 of 1

shell_exec($cmd) is not working

Posted: Thu Sep 25, 2008 5:11 am
by kapil1089theking
I have code in my output.php page as:

Code: Select all

 
        $cmd = "./a.out input/1.pbm output.pbm";
        $kk = shell_exec($cmd);
        echo $kk;
 
But, when I access/execute the page, there is nothing printed, I wanted to run a c-program which takes a picture file as input and outputs a picture file. The program runs in about 1-2 second, I guess the output page comes out before the code is run/executed.

I am developing this on linux platform, so when i execute the same page with:

Code: Select all

 
$ php output.php
 
it works fine.
Where is the bug in my code?

Re: shell_exec($cmd) is not working

Posted: Thu Sep 25, 2008 5:23 am
by kapil1089theking
In my log file it says sh: ./a.out: permission denied, what should I do?

Re: shell_exec($cmd) is not working

Posted: Thu Sep 25, 2008 7:23 am
by Darkzaelus
Have you set the CHMOD permissions correctly?

Re: shell_exec($cmd) is not working

Posted: Thu Sep 25, 2008 7:25 am
by VladSun
++Darkzaelus

And use absolute paths.

Re: shell_exec($cmd) is not working

Posted: Thu Sep 25, 2008 7:33 am
by Darkzaelus
I know nout about linux, but yea, absolute paths are a must.

Cheers,

Darkzaelus.

Re: shell_exec($cmd) is not working

Posted: Thu Sep 25, 2008 7:50 am
by kapil1089theking
It says permission denied, is it possible that it occurs for not having absolute path?
I don't think So,

Its something related to CHMOD I guess,
The user is apache and the group is apache I have done chmod 755 -R folder
still not working,

Or if it has the problem with absolute path then please help me to know it better and debug the same.

Re: shell_exec($cmd) is not working

Posted: Thu Sep 25, 2008 7:55 am
by VladSun
You need:
- a.out with permissions set to 755 (also, it should not insist that you are really root by using getuid() function )
- directory and files which a.out reads from should be readable by Apache user/group;
- directory and files which a.out writes to should be writeable by Apache user/group;

Using absolute paths will help you solve path related issues.