LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 11-04-2005, 07:36 PM   #1
pEeDy
LQ Newbie
 
Registered: Aug 2005
Posts: 8

Rep: Reputation: 0
[PHP] Sending shell commands from PHP


Hey guys, I am building a webinterface to set up a Quake 3 Arena server on my Linux server. I have the variables $map, $timelimit, $fraglimit etc..

I want the PHP file to send out a command like: .

/q3ded +set dedicated 1 +exec ffa.cfg +map q3dm17 +set pure 0 &

I tried exec() and shell_exec() but I can't get it to work?
Does somebody have an idea?
 
Old 11-04-2005, 07:47 PM   #2
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,537

Rep: Reputation: 119Reputation: 119
Maybe give the full path for q3ded, also on a side note,
the + sign before the options is not POSIX compliant...

Try the inversed quotes :
PHP Code:
$pid = `/usr/local/bin/q3ded +set dedicated 1 +exec ffa.cfg +map /home/3d/q3dm17 +set pure 0 &`; 
 
Old 11-04-2005, 07:53 PM   #3
pEeDy
LQ Newbie
 
Registered: Aug 2005
Posts: 8

Original Poster
Rep: Reputation: 0
I tried:

$pid = "/usr/local/games/quake3/./q3ded +set dedicated 1 +exec ffa.cfg +map q3dm17 +set pure 0 &";
shell_exec($pid) or die();

and

$pid = `/usr/local/games/quake3/./q3ded +set dedicated 1 +exec ffa.cfg +map q3dm17 +set pure 0 &`;
shell_exec($pid) or die();

and I tried replacing shell_exec with exec, but it keeps on giving no output, and not starting the server


Edit: or maybe it is because the webserver is logged in as apache and has no rights to start it? If so, how do I give those rights to apache?

Last edited by pEeDy; 11-04-2005 at 07:59 PM.
 
Old 11-04-2005, 08:01 PM   #4
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,537

Rep: Reputation: 119Reputation: 119
Try to set the path for ffa.cfg and q3dm17 files as well

Do no use the shell_exec() with the inversed quote as the
inversed quotes mean execute whatever is between them

Maybe before do a test with PHP, you should try to test
the command (with full path for all files) in a console to see
 
Old 11-04-2005, 08:06 PM   #5
pEeDy
LQ Newbie
 
Registered: Aug 2005
Posts: 8

Original Poster
Rep: Reputation: 0
If I run this command:

/usr/local/games/quake3/./q3ded +set dedicated 1 +exec ffa.cfg +map q3dm17 +set pure 0 &

through 'Command Shell' in Webmin, I get an output (it still doesn't start, but that's problem #2 now).

When I try it with my code:

$command = "/usr/local/games/quake3/./q3ded +set dedicated 1 +exec ffa.cfg +map q3dm17 +set pure 0 &";
$output = shell_exec($command);
echo($output);

I don't get any output? What's up with that?

Edit: when I put in 'uptime' as $command, it does give me the correct output...

Last edited by pEeDy; 11-04-2005 at 08:07 PM.
 
  


Reply


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
Sending email in PHP, what headers should I use? abefroman Programming 2 10-12-2005 02:49 AM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 11:51 AM
Sending email with PHP jacksmash Programming 7 03-10-2004 05:10 PM
Trouble sending mails with php Wagner Linux - Networking 3 12-15-2003 10:41 PM
PHP to run Shell commands Gear_freak2000 Linux - Software 4 06-04-2003 05:39 AM


All times are GMT -5. The time now is 07:04 AM.

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