Page 1 of 1

terminal commands on the server ?

Posted: Fri Feb 20, 2009 6:59 pm
by garyed
Can I run a command from a php file that will actually run on my server as if I were typing the same command in a linux terminal?
If I run this code from a remote browser the ls command outputs to the browser & the aplay doesn't do anything.
I want the ls to output to my servers terminal & also the beep too.
Is this possible ?

Code: Select all

<?php 
$aa = "ls /var/www";
system ($aa);
$bb = "aplay /var/www/beep.wav";
system = ($bb);
 

Re: terminal commands on the server ?

Posted: Fri Feb 20, 2009 7:15 pm
by Eran
exec() and/or shell_exec() are probably what you are looking for.
http://www.php.net/manual/en/function.shell-exec.php
http://www.php.net/function.exec

Re: terminal commands on the server ?

Posted: Fri Feb 20, 2009 7:27 pm
by garyed
pytrin wrote:exec() and/or shell_exec() are probably what you are looking for.
http://www.php.net/manual/en/function.shell-exec.php
http://www.php.net/function.exec
I've tried them both & I can't get them to work.
I've been searching the net for two solid days & I can't find the answer so if anyone has one I wish they would post a simple code to use the
"aplay" command because that is what I'm really trying to do. Have someone click on a page & have aplay play the beep.wav file on my computer (running Apache).

Re: terminal commands on the server ?

Posted: Sat Feb 21, 2009 10:19 am
by VladSun
1. Use absolute path. E.g.:

Code: Select all

exec('/usr/local/bin/aplay /var/www/beep.wav');
2. Print error output to see what's wrong:

Code: Select all

exec('/usr/local/bin/aplay /var/www/beep.wav 2>&1');