Re: Capturing shell command output.

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

 



On 8/27/07, Richard Lynch <ceo@xxxxxxxxx> wrote:
> You could look into using "named pipes" in PHP.
>
> I think PHP is already folding stderr into stdout (2>&1) for you.
>
> You could also try using http://php.net/exec instead of the backticks
> to get a separate error code if there is an error.
>
> On Sat, August 18, 2007 3:26 pm, shiplu 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
> >
> >
>
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?
>
>
I have tried same file as cli and as webpage. I don't know why only
cli version works nicely.  There may be some issue. But my technique
has some advantages. It can run command asynchronously. Thats what i
need for my application. I can create command queue. I and I can get
the completion percentage from there.
Whatever, I wish I could know those issues.
Rather it could happen that, php-apache framework is doing something
that I am unaware of.

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