cannot execute some commands
Posted: Sun May 10, 2009 6:06 pm
Hi folks,
I'm trying to use shell_exec(), exec(), system(), or any function of that nature to execute a command, but it only seems to want to execute commands that are built-in to the Bash shell. For example, this works fine:
When I visit my php page I see the contents of my /etc/passwd file. However, if I try calling a shell script or any other binary it fails. The commands are definitely in my PATH variable (not sure about the apache user's PATH) so I have tried fully-qualifying the commands like this:
Nothing prints when I attempt this. I even changed it to use system() instead of shell_exec() and checked the return code like this:
Doing so results in a return code of zero being printed to the browser, but the actual output of the command never returns anything like it should. So apparently it's executing the command but for some odd reason nothing get stored into $myOutput. The same thing happens if I attempt to invoke a shell script -- the return code is fine but the output just isn't there.
I have safe mode turned off, and safe_mode_exec_dir = /usr/local/php/bin. I tried putting scripts into this directory and executing them but that doesn't work either.
Am I missing something here? Why can't I invoke a script or other executable from my php code?
I'm trying to use shell_exec(), exec(), system(), or any function of that nature to execute a command, but it only seems to want to execute commands that are built-in to the Bash shell. For example, this works fine:
Code: Select all
$command = "cat /etc/passwd";
$myOutput = shell_exec($command);
echo "<pre>".$myOutput."</pre>";
Code: Select all
$command = "/usr/bin/java -version";
$myOutput = shell_exec($command);
echo "<pre>".$myOutput."</pre>";
Code: Select all
$command = "/usr/bin/java -version";
$myOutput = system($command, $rc);
echo "$rc";
echo "<pre>".$myOutput."</pre>";
I have safe mode turned off, and safe_mode_exec_dir = /usr/local/php/bin. I tried putting scripts into this directory and executing them but that doesn't work either.
Am I missing something here? Why can't I invoke a script or other executable from my php code?