Page 1 of 1

exec() not working

Posted: Mon Jun 14, 2010 6:24 am
by Cepheus
Hi,

Im trying to run the exec() function using the code:

Code: Select all

<?php
	
	exec("whoami", $output);
	print_r($output);
?>
This returns a blank array, and in the apache error logs show: "sh: /whoami: No such file or directory". Safe mode is off.

whoami works fine in the console, as does any other applicatons i try to run (i.e. ffmpeg), but both fail using exec().

If anyone has any ideas on how to get this working it would be much appreciated.

Thanks in advance.

Re: exec() not working

Posted: Mon Jun 14, 2010 10:27 am
by andyhoneycutt
Seems to work fine on my system. Have you tried the full path to the binary? Perhaps:

Code: Select all

exec('/usr/bin/whoami',$output);
print_r($output); 

Re: exec() not working

Posted: Mon Jun 14, 2010 12:09 pm
by Cepheus
Still no joy I’m afraid using the full path. I've checked the binaries permissions and they all seem ok. Apart from safe mode, is there anything else and needs to be specifically enabled/disabled?

Re: exec() not working

Posted: Mon Jun 14, 2010 12:34 pm
by andyhoneycutt
if you add the return code parameter to the exec() function, what result do you get out of it?

Code: Select all

exec("whoami", $output, $code);
print_r($output);
print_r($code); 

Re: exec() not working

Posted: Mon Jun 14, 2010 5:41 pm
by Cepheus
It's returning "127" as a result.

Re: exec() not working

Posted: Tue Jun 15, 2010 1:58 am
by VladSun
Try

Code: Select all

exec("whoami 2>&1", $output, $code);
print_r($output);
print_r($code); 

Re: exec() not working

Posted: Tue Jun 15, 2010 7:19 pm
by Cepheus
That got it working, thanks!