shell_exec($cmd) is not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

shell_exec($cmd) is not working

Post 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?
kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

Re: shell_exec($cmd) is not working

Post by kapil1089theking »

In my log file it says sh: ./a.out: permission denied, what should I do?
Darkzaelus
Forum Commoner
Posts: 94
Joined: Tue Sep 09, 2008 7:02 am

Re: shell_exec($cmd) is not working

Post by Darkzaelus »

Have you set the CHMOD permissions correctly?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: shell_exec($cmd) is not working

Post by VladSun »

++Darkzaelus

And use absolute paths.
There are 10 types of people in this world, those who understand binary and those who don't
Darkzaelus
Forum Commoner
Posts: 94
Joined: Tue Sep 09, 2008 7:02 am

Re: shell_exec($cmd) is not working

Post by Darkzaelus »

I know nout about linux, but yea, absolute paths are a must.

Cheers,

Darkzaelus.
kapil1089theking
Forum Commoner
Posts: 46
Joined: Wed May 28, 2008 1:51 pm
Location: Kolkata, India
Contact:

Re: shell_exec($cmd) is not working

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: shell_exec($cmd) is not working

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply