LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   [PHP] Sending shell commands from PHP (http://www.linuxquestions.org/questions/programming-9/%5Bphp%5D-sending-shell-commands-from-php-380047/)

pEeDy 11-04-2005 07:36 PM

[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?

keefaz 11-04-2005 07:47 PM

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 &`; 


pEeDy 11-04-2005 07:53 PM

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?

keefaz 11-04-2005 08:01 PM

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

pEeDy 11-04-2005 08:06 PM

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...


All times are GMT -5. The time now is 12:09 AM.