Click to See Complete Forum and Search --> : [SOLVED]Problems with executing binnaries with php exec()


wieza
04-06-2006, 06:48 AM
Hi. I have problems with executing external programms in php with exec() and system(). When i am trying to execute some shell commands eg system('ls'), exec('whoami') there is no problem
, with my binaries (the simplest hello world program in c++) - no problem. But programms, which i've installed in shell as root user(./configure make make install) before, don't work.' For example i've installed cvs. When i want to open page
<?php
system('cvs');
?>
I'am getting blank page. I was trying to give whole path system('/usr/local/bin/cvs') it doesn't work.

My environment:
Suse Linux
PHP Version 4.3.4
Apache
safe_mode = Off

File permission for cvs are 755.

I've read somewhere that it could be problem when program which i want to execute in php is using shared libraries, but i don't know anything more.

cybertron
04-07-2006, 11:03 PM
Hmm, I'm a little surprised that system('ls') would display anything by itself either. That function returns a string, so you should have to echo it before it will be displayed on the page. Also, system only returns the last line of the output, so if there's an extra newline the output might actually be blank. You might want to try the backtick operator or passthru function instead if you want all of the output.

Give this a shot and see if it works better for you:

<?php
echo `/usr/local/bin/cvs`; // Note: not single quotes, backtick is on the ~ key
?>

wieza
04-08-2006, 05:05 AM
Hi.system -- Execute an external program and display the output. It's no problem. I tried all the possibilities(system, exec, passtrough,shell_exec, ``).

Exec function can return return status of the executed unix command. When i want exec('cvs') it returns 127 :confused:

cybertron
04-08-2006, 11:44 AM
Whoops, you're right. I was just looking at the return value of system. Anyway, one possibility is to add 2>&1 to the end of your command line so stderr will also get printed. I can't find anything specifying exactly what return code 127 means, but presumably it's an error of some sort so the output is probably in stderr.

wieza
04-08-2006, 01:01 PM
system('cvs 2>&1'); ---> sh: line 1: cvs: command not found

when i logged to shell as wwwrun user(the same which apache runs) there was no problem to execute those commands in shell

cybertron
04-08-2006, 05:49 PM
Try it with the full path. It's possible that when PHP executes the command it doesn't set things like the PATH variable the same as a normal shell would. Hopefully that will give you a different error that will shed some light on what's actually wrong.

wieza
04-10-2006, 07:48 AM
system('/usr/local/bin/cvs 2>&1'); it works!

thank you very much

cybertron
04-10-2006, 01:06 PM
Glad to hear it. I suppose that if you just run CVS all of the output goes to stderr because you need parameters, so that makes sense.