Capturing shell command output.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



HI,
I am working on a PHP project that interacts with command  line utilities.
My php is running by apache. Means I am not running any php CLI.

here is the function that I am using for capturing command output.

function run_command($comamnd){
$ret=`$command 1> COMMAND.OUT 2>1`;
$contents=get_file_contents("COMMAND.OUT");
return $contents;
}

The function does not work. If I use any shell command like ls, cat,
echo, set. it works.
But If I use any utility like, mpg321, cd-info. It does not work. It
outputs a blank string.
I used system(), passthru() with both "2&>1" and "2>1". But no out put.
All the time, its blank.
Even I used a shell script "run.sh"
run.sh contents:
=====================================
#!/bin/sh
sh COMMAND 1> COMMAND.OUT 2&>1
cat COMMAND.OUT
echo 0 > COMMAND
=====================================

I called this script by this function
function run_command($command){
               $h=fopen("COMMAND","w");
               fwrite($h,$command);
               fclose($h);
               ob_start();
               passthru("./run.sh");
               $ret = ob_get_contents();
               ob_end_clean();
               return $ret;
}

and by this.

function run_command($command){
               $h=fopen("COMMAND","w");
               fwrite($h,$command);
               fclose($h);
               return system("./run.sh");
}

Please help me. or show me some way.


-- 
shout at http://shiplu.awardspace.com/

Available for Hire/Contract/Full Time

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux