LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   apache php - executing commands using system(), problems (https://www.linuxquestions.org/questions/programming-9/apache-php-executing-commands-using-system-problems-645064/)

Sambojambo 05-27-2008 09:21 AM

apache php - executing commands using system(), problems
 
I sure that there's going to be a quick answer to this. I'm calling a command through the system() function in php.

PHP Code:

$cmd 'tide -ml -fh -o $output ';
system($cmd); 

When I run the script through www-data it won't execute. I've checked the permissions on the bin and it looks fine. I'm confused as www-data can execute other bins in the same folder with the same permissions. This is on a standard install of Ubuntu Hardy.

Code:

sam@nugget:/$ ls -la /usr/bin/tide | grep tide
-rwxr-xr-x 1 root root 370852 2008-04-03 21:53 /usr/bin/tide

I'm not the most experienced system admin - I must be missing something obvious?

Thanks in advance for any help

Hko 05-27-2008 11:32 AM

One thing is wrong dor sure: When using single quotes (' '), as you did, the variable $output will not be replaced with the value of $output. Use double quotes (" ") instead.

Also, what is the value of $output? Can www-data really write there?
You can Check with this: $cmd = "tide -ml -fh -o $output 2>&1"; Any errors from the 'tide' program will show in you browser.

I noticed 'tide' outputs html code. You could also try without the -o $output part first. The html from 'tide' will show nicely in the browser.

Complete example:
PHP Code:

<html>
    <head>
        <title>Tides</title>
    </head>
    <body>
        <?php
            $output 
'/tmp/tide.html';
            
$cmd "tide -ml -fh";
            
// $cmd = "tide -ml -fh -o $output 2>&1";
            // $cmd = "tide -ml -fh -o $output";
            
system($cmd);
        
?>
    </body>
</html>


Sambojambo 05-28-2008 05:19 AM

Late night silly mistake...
 
Thanks for your reply Hko - and your simple script help pin down my silly mistake quickly. Apache was unable to write to the $output file which I was soon able to see with '2>&1'. The single/double quote issue was just a typo in the post.

Thanks again

seraphim172 05-29-2008 11:52 AM

Just a note in general: If you run any system commands in PHP be prepared for time-out problems if the operations takes long to finish. Fore example, calling ghostscript to merge a set of PDF files can take longer than the web server allows the PHP process to run. This is often a problem with osCommerce modules.

Linux Archive


All times are GMT -5. The time now is 01:05 AM.