FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » redirect stdout and stderr to PHP variables?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: redirect stdout and stderr to PHP variables? [message #176821 is a reply to message #176815] Fri, 27 January 2012 10:11 Go to previous messageGo to previous message
crankypuss is currently offline  crankypuss
Messages: 147
Registered: March 2011
Karma:
Senior Member
On 01/26/2012 08:18 AM, Erwin Moller wrote:
> On 1/26/2012 3:11 PM, crankypuss wrote:
>> On 01/26/2012 05:25 AM, M. Strobel wrote:
>>> Am 26.01.2012 12:14, schrieb crankypuss:
>>>> On 01/26/2012 03:43 AM, Erwin Moller wrote:
>>>> > On 1/26/2012 10:27 AM, crankypuss wrote:
>>>> >> On 01/26/2012 02:00 AM, Tim Streater wrote:
>>>> >>> In article<jfr340125sq(at)news4(dot)newsguy(dot)com>,
>>>> >>> crankypuss<no(at)email(dot)thanks> wrote:
>>>> >>>
>>>> >>>> On 01/25/2012 03:53 PM, crankypuss wrote:
>>>> >>>>> On 01/25/2012 02:46 PM, M. Strobel wrote:
>>>> >>>>>> php> $res1 = exec('rm this-does-really-not-exist.php 2>&1', $a,
>>>> >>>> $rc);
>>>> >>>>>> php> echo $rc;
>>>> >>>>>> 1
>>>> >>>>>> php> print_r($a);
>>>> >>>>>> Array
>>>> >>>>>> (
>>>> >>>>>> [0] => rm: Entfernen von „this-does-really-not-exist.php“ nicht
>>>> >>>>>> möglich: Datei
>>>> >>>>>> oder Verzeichnis nicht gefunden
>>>> >>>>>> )
>>>> >>>>>> php>
>>>> >>>>>
>>>> >>>>> Thanks, will try these in the morning.
>>>> >>>>
>>>> >>>> BTW, where is this syntax documented? I'd prefer understanding
>>>> >>>> it to
>>>> >>>> using magic.
>>>> >>>
>>>> >>> Which syntax, exactly? exec is documented in the PHP online docs.
>>>> >>
>>>> >> Sorry, I've been unable to find the bit about redirecting stdout and
>>>> >> stderr to PHP variables, can you point me to that? Yes, exec()
>>>> >> provides
>>>> >> an optional&$output argument which in effect redirects stdout to the
>>>> >> varialble, but I see no way to obtain stderr separately. Thanks.
>>>> >
>>>> > Hi crankypuss,
>>>> >
>>>> > You only see this redirecting in functions that handle with STDERR and
>>>> > STDOUT, functions like exec() you already use.
>>>> > When you are working within 'normal' PHP (as in "No external processes
>>>> > invoked by user", so no exec() and the like) you don't have the
>>>> > concept
>>>> > of STDERR directly, nor do you need it.
>>>> > Of course: errors can still occur, but PHP will handle them. You can
>>>> > modify HOW you want PHP to handle them (logging into file/errorlog,
>>>> > put
>>>> > them on screen, invoke some custom-errorhandler/etc).
>>>> >
>>>> > To put it very simple (and probably incorrect) to get the general
>>>> > idea:
>>>> > You can think of PHP in relation with STDIN and STDOUT and STDERR like
>>>> > this:
>>>> >
>>>> > STDIN for PHP is what is feeded to PHP (via Apache, or commandline)
>>>> > So that consists typically of things like (part of) URL, cookies,
>>>> > referrer, etc.
>>>> >
>>>> > STDOUT is what PHP produces and is returned to the client (most of the
>>>> > time with a webserver inbetween).
>>>> >
>>>> > STDERR is where PHP directs its erorrs to. (Think logfile, and/or to
>>>> > STDOUT: this is all configurable.)
>>>> >
>>>> > But you don't see STDIN/STDOUT/STDERR when you work with PHP without
>>>> > using exec().
>>>> >
>>>> > Regards,
>>>> > Erwin Moller
>>>>
>>>> So how do you capture only STDERR when using exec() ?
>>>
>>> You can not capture only stderr, because exec returns only stdout. So
>>> you only can
>>> redirect stderr to stdout.
>>
>> As far as I'm concerned that's pretty useless.
>>
>>> You can do it with http://es.php.net/manual/en/function.proc-open.php
>>> Maybe you should explain what your basic problem is.
>>
>> I have. Lots of stdout lines with a few stderr lines, I want to output
>> the stderr lines *after* stdout instead of interspersed.
>>
>
>
> Hi Crankypuss,
>
> Read this:
> http://nl.php.net/manual/en/function.proc-open.php
>
> It is a little more complicated, but you can capture what you need
> (STDERR in this case).

It looks like it might be what I'm looking for, but it will be a while
before I can get around to studying/trying it; thanks very much.

> Very off topic:
> Concerning your wish to intergrate PHP with a windowing environment, I
> found this:
>
> http://en.wikipedia.org/wiki/PHP-Qt
>
> I haven't used it myself, only with C++ so I have no clue how good it
> all is, but QT is solid.

Yes, I found that several days ago. It's object oriented, which is
rather a turnoff for me since all my PHP is currently strictly
procedural (mostly because eventually I'll port it to C, not C++, and
will probably do the bulk of that with a conversion program), there's no
repository that looks clearly trustworthy, and I don't care to build it
from source (because at this point in time I am too stoopid to do that
and have too much other stuff going on).

I'm keeping my eyes open but my current thinking is to either build a
pseudo-browser (based on gekko?) or modify Firefox about the head and
shoulders until it knows how to invoke PHP the way apache invokes it.

Thanks much.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: enter search term via code?
Next Topic: FounderDating - Helping entrepreneurs find their co-founder & start companies!
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 21:53:24 GMT 2024

Total time taken to generate the page: 0.04415 seconds