LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Executing UNIX command from PHP script (https://www.linuxquestions.org/questions/programming-9/executing-unix-command-from-php-script-420771/)

ckoniecny 03-01-2006 08:35 PM

Executing UNIX command from PHP script
 
How can I execute a UNIX command from a PHP script?

Is there someway of doing the following:

PHP Code:

<?php
     
echo "<HTML>";
     echo 
"<TITLE>";
     echo 
"<BODY>";
     echo `
uname -a`;         <=== How do you execute this?
     echo 
"</TITLE>";
     echo 
"</BODY>";
     echo 
"</HTML>";
?>


ckoniecny 03-01-2006 08:44 PM

Nevermind, I figured it out.

sipsipi 03-01-2006 09:20 PM

Well, whatdja do?

ckoniecny 03-01-2006 10:42 PM

This is what I am using.

http://us3.php.net/manual/en/function.system.php

But I do have another question, how can I set the PATH for commands?

For example,

If I run "php -f test.php"


PHP Code:

<?php
echo '<pre>';

// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line system('ls'$retval);

// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' 
$last_line '
<hr />Return value: ' 
$retval;
?>


the result is:
sh: /usr/local/php/bin/ls: No such file or directory


All times are GMT -5. The time now is 09:15 PM.