Re: Capturing shell command output.

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

 



You may want to look into shell_exec, which executes a command and returns
the output. If you're accepting arguments from user input, don't forget
proper use of escapeshellcmd and escapeshellarg ;-).

Something else that might cause your commands from failing, is that the
utilities are not inside apache's PATH - trying to call them by there
absolute filename can help out. Have you inspected your error_log? There
often tends to be a lot of useful stuff in there.

Good luck!
Wouter

On 18/08/07, shiplu <shiplu.net@xxxxxxxxx> wrote:
>
> 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
>
>


-- 
Interpotential.com
Phone: +31615397471

[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