Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-27-2008, 09:21 AM   #1
LQ Newbie
Registered: Feb 2008
Location: UK
Distribution: Ubuntu - Hardy Heron
Posts: 10

Rep: Reputation: 0
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 ';
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.

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
Old 05-27-2008, 11:32 AM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
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:
$cmd "tide -ml -fh";
// $cmd = "tide -ml -fh -o $output 2>&1";
            // $cmd = "tide -ml -fh -o $output";

Last edited by Hko; 05-27-2008 at 11:37 AM.
Old 05-28-2008, 05:19 AM   #3
LQ Newbie
Registered: Feb 2008
Location: UK
Distribution: Ubuntu - Hardy Heron
Posts: 10

Original Poster
Rep: Reputation: 0
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
Old 05-29-2008, 11:52 AM   #4
Registered: May 2008
Posts: 101

Rep: Reputation: 15
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

Last edited by seraphim172; 06-25-2008 at 04:42 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
executing shell commands in PHP mohtasham1983 Programming 7 09-14-2007 11:04 AM
Executing system commands in a php script atiq Linux - Server 2 02-26-2007 09:45 AM
Executing shell commands through PHP!!! Richtown Linux - Newbie 6 04-12-2006 02:57 PM
PHP executing System command abdul_zu Linux - General 4 12-28-2005 02:14 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration