Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #4623

Re: redirect stdout and stderr to PHP variables?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!not-for-mail
From "M. Strobel" <sorry_no_mail_here@nowhere.dee>
Newsgroups comp.lang.php
Subject Re: redirect stdout and stderr to PHP variables?
Date Thu, 26 Jan 2012 13:25:41 +0100
Lines 91
Message-ID <9ocv25F4g4U1@mid.uni-berlin.de> (permalink)
References <jfpm810drs@news2.newsguy.com> <9obbi3F87kU1@mid.uni-berlin.de> <jfq1651o17@news2.newsguy.com> <jfr340125sq@news4.newsguy.com> <timstreater-FCEA15.09002026012012@news.individual.net> <jfr6a903041@news1.newsguy.com> <4f212e5b$0$6873$e4fe514c@news2.news.xs4all.nl> <jfrcis01k0n@news3.newsguy.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de 8jZ4tOam6ZZp2F3jWoIjRACrGX8YABinq9cUrqAMKvleoqIUY=
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.24) Gecko/20111101 Thunderbird/3.1.16
In-Reply-To <jfrcis01k0n@news3.newsguy.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.php:4623

Show key headers only | View raw


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@news4.newsguy.com>,
>>>> crankypuss <no@email.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.

You can do it with http://es.php.net/manual/en/function.proc-open.php

Maybe you should explain what your basic problem is. Mentioning the environment so we
do not have to guess.

/Str.

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-25 12:47 -0700
  Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-25 22:42 +0100
  Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-25 22:46 +0100
    Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-25 15:53 -0700
      Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-26 01:33 -0700
        Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-26 09:46 +0100
          Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-26 02:23 -0700
            Re: redirect stdout and stderr to PHP variables? Michael Fesser <netizen@gmx.de> - 2012-01-26 14:35 +0100
            Re: redirect stdout and stderr to PHP variables? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-01-26 07:49 -0600
        Re: redirect stdout and stderr to PHP variables? Tim Streater <timstreater@greenbee.net> - 2012-01-26 09:00 +0000
          Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-26 02:27 -0700
            Re: redirect stdout and stderr to PHP variables? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-01-26 11:43 +0100
              Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-26 04:14 -0700
                Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-26 13:25 +0100
                Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-26 07:11 -0700
                Re: redirect stdout and stderr to PHP variables? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-01-26 16:18 +0100
                Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-27 03:11 -0700
  Re: redirect stdout and stderr to PHP variables? Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-25 17:25 -0500
    Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-27 03:16 -0700
      Re: redirect stdout and stderr to PHP variables? Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-27 08:49 -0500
        Re: redirect stdout and stderr to PHP variables? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-01-27 16:00 +0100
          Re: redirect stdout and stderr to PHP variables? Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-27 10:12 -0500
            Re: redirect stdout and stderr to PHP variables? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-01-27 10:37 -0600
              Re: redirect stdout and stderr to PHP variables? Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-30 21:37 -0500
            Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-28 05:00 -0700
  Re: redirect stdout and stderr to PHP variables? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-01-25 16:52 -0600
    Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-27 03:22 -0700
      Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-27 12:25 +0100
        Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-28 05:03 -0700
          Re: redirect stdout and stderr to PHP variables? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-01-28 11:40 -0600
          Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-29 00:40 +0100
  Re: redirect stdout and stderr to PHP variables? Curtis Dyer <dyer85@gmail.com> - 2012-01-25 22:56 +0000
    Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-27 03:23 -0700
      Re: redirect stdout and stderr to PHP variables? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-01-27 11:42 +0100
        Re: redirect stdout and stderr to PHP variables? Curtis Dyer <dyer85@gmail.com> - 2012-01-29 04:56 +0000
  Re: redirect stdout and stderr to PHP variables? [solved] crankypuss <no@email.thanks> - 2012-02-01 05:22 -0700

csiph-web