Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #4611 > unrolled thread
| Started by | crankypuss <no@email.thanks> |
|---|---|
| First post | 2012-01-25 12:47 -0700 |
| Last post | 2012-02-01 05:22 -0700 |
| Articles | 20 on this page of 36 — 8 participants |
Back to article view | Back to comp.lang.php
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
Page 1 of 2 [1] 2 Next page →
| From | crankypuss <no@email.thanks> |
|---|---|
| Date | 2012-01-25 12:47 -0700 |
| Subject | redirect stdout and stderr to PHP variables? |
| Message-ID | <jfpm810drs@news2.newsguy.com> |
I'm sure there's a way to do this, probably some simple syntax I've not run into and am too stupid to find in the manual or through google-fu or otherwise. I'd like to issue an arbitrary shell command in a subroutine and have it return an array that contains one element representing stdout and another element representing stderr. For example, using tar to deal with a bazillion files, error messages might not be seen when specifying verbose output; I'd like to collect them and display after stdout. I've not found any syntax, yet, for redirecting to a PHP variable rather than some file. tia.
[toc] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-01-25 22:42 +0100 |
| Message-ID | <9obbadF6enU1@mid.uni-berlin.de> |
| In reply to | #4611 |
Am 25.01.2012 20:47, schrieb crankypuss:
> I'm sure there's a way to do this, probably some simple syntax I've not run into and
> am too stupid to find in the manual or through google-fu or otherwise.
>
> I'd like to issue an arbitrary shell command in a subroutine and have it return an
> array that contains one element representing stdout and another element representing
> stderr.
>
> For example, using tar to deal with a bazillion files, error messages might not be
> seen when specifying verbose output; I'd like to collect them and display after stdout.
>
> I've not found any syntax, yet, for redirecting to a PHP variable rather than some file.
>
> tia.
No problem here:
php > $res = shell_exec('rm this-does-really-not-exist.php 2>&1');
php > echo $res;
rm: Entfernen von „this-does-really-not-exist.php“ nicht möglich: Datei oder
Verzeichnis nicht gefunden
php >
Maybe you drop this requirement "array of...".
/Str.
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-01-25 22:46 +0100 |
| Message-ID | <9obbi3F87kU1@mid.uni-berlin.de> |
| In reply to | #4611 |
Am 25.01.2012 20:47, schrieb crankypuss:
> I'm sure there's a way to do this, probably some simple syntax I've not run into and
> am too stupid to find in the manual or through google-fu or otherwise.
>
> I'd like to issue an arbitrary shell command in a subroutine and have it return an
> array that contains one element representing stdout and another element representing
> stderr.
>
> For example, using tar to deal with a bazillion files, error messages might not be
> seen when specifying verbose output; I'd like to collect them and display after stdout.
>
> I've not found any syntax, yet, for redirecting to a PHP variable rather than some file.
>
> tia.
Or like that, if you are fond of arrays:
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 >
/Str.
[toc] | [prev] | [next] | [standalone]
| From | crankypuss <no@email.thanks> |
|---|---|
| Date | 2012-01-25 15:53 -0700 |
| Message-ID | <jfq1651o17@news2.newsguy.com> |
| In reply to | #4613 |
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.
[toc] | [prev] | [next] | [standalone]
| From | crankypuss <no@email.thanks> |
|---|---|
| Date | 2012-01-26 01:33 -0700 |
| Message-ID | <jfr340125sq@news4.newsguy.com> |
| In reply to | #4614 |
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.
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-01-26 09:46 +0100 |
| Message-ID | <9oci7iF5giU1@mid.uni-berlin.de> |
| In reply to | #4615 |
Am 26.01.2012 09:33, schrieb crankypuss:
> 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.
Hey, I just booted my system in the morning, and checked for news...
see here: http://www.gnu.org/software/bash/manual/bashref.html#Redirections
The windows cmd.exe works quite the same in this point.
/Str.
[toc] | [prev] | [next] | [standalone]
| From | crankypuss <no@email.thanks> |
|---|---|
| Date | 2012-01-26 02:23 -0700 |
| Message-ID | <jfr61s02vig@news1.newsguy.com> |
| In reply to | #4616 |
On 01/26/2012 01:46 AM, M. Strobel wrote:
> Am 26.01.2012 09:33, schrieb crankypuss:
>> 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.
>
> Hey, I just booted my system in the morning, and checked for news...
>
> see here: http://www.gnu.org/software/bash/manual/bashref.html#Redirections
>
> The windows cmd.exe works quite the same in this point.
>
> /Str.
Sorry, I might be more dense than I realized, but what does bash have to
do with php here? I might not (and often will not) be running a cli
script but rather running commands as part of generating an html page
for a web server.
[toc] | [prev] | [next] | [standalone]
| From | Michael Fesser <netizen@gmx.de> |
|---|---|
| Date | 2012-01-26 14:35 +0100 |
| Message-ID | <lgl2i75po7fqnu1g759dvt7m1vhcata26j@mfesser.de> |
| In reply to | #4618 |
.oO(crankypuss) >Sorry, I might be more dense than I realized, but what does bash have to >do with php here? Running exec() and the like invokes a shell, which then executes the given command. Redirecting STDERR ist part of that shell, not PHP. Micha -- http://mfesser.de/blickwinkel
[toc] | [prev] | [next] | [standalone]
| From | "Peter H. Coffin" <hellsop@ninehells.com> |
|---|---|
| Date | 2012-01-26 07:49 -0600 |
| Message-ID | <slrnji2mg7.51n.hellsop@nibelheim.ninehells.com> |
| In reply to | #4618 |
On Thu, 26 Jan 2012 02:23:07 -0700, crankypuss wrote: > On 01/26/2012 01:46 AM, M. Strobel wrote: > >> Am 26.01.2012 09:33, schrieb crankypuss: >> >>> BTW, where is this syntax documented? I'd prefer understanding it to >>> using magic. >> >> Hey, I just booted my system in the morning, and checked for news... >> >> see here: >> http://www.gnu.org/software/bash/manual/bashref.html#Redirections >> >> The windows cmd.exe works quite the same in this point. >> >> /Str. > > Sorry, I might be more dense than I realized, but what does bash have > to do with php here? I might not (and often will not) be running a cli > script but rather running commands as part of generating an html page > for a web server. That, or some other shell depending (IIRC) what shell the user ID that the script is running under, is what is going to parse the command you pass to exec(). That, too, is not handled by magic. -- Babbage pioneered IT management: his project took vast sums of cash, the spec kept changing, and it ultimately failed to deliver. Turing scavenged supplies and knocked together something that worked and solved the problem - reward? Arrest and castration. Which one feels most like your career? -- Peter Corlett
[toc] | [prev] | [next] | [standalone]
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Date | 2012-01-26 09:00 +0000 |
| Message-ID | <timstreater-FCEA15.09002026012012@news.individual.net> |
| In reply to | #4615 |
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.
--
Tim
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
[toc] | [prev] | [next] | [standalone]
| From | crankypuss <no@email.thanks> |
|---|---|
| Date | 2012-01-26 02:27 -0700 |
| Message-ID | <jfr6a903041@news1.newsguy.com> |
| In reply to | #4617 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Erwin Moller <erwinmollerusenet@xs4all.nl> |
|---|---|
| Date | 2012-01-26 11:43 +0100 |
| Message-ID | <4f212e5b$0$6873$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #4619 |
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
--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
[toc] | [prev] | [next] | [standalone]
| From | crankypuss <no@email.thanks> |
|---|---|
| Date | 2012-01-26 04:14 -0700 |
| Message-ID | <jfrcis01k0n@news3.newsguy.com> |
| In reply to | #4620 |
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() ?
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-01-26 13:25 +0100 |
| Message-ID | <9ocv25F4g4U1@mid.uni-berlin.de> |
| In reply to | #4621 |
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.
[toc] | [prev] | [next] | [standalone]
| From | crankypuss <no@email.thanks> |
|---|---|
| Date | 2012-01-26 07:11 -0700 |
| Message-ID | <jfrmu501u6t@news3.newsguy.com> |
| In reply to | #4623 |
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@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.
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.
> Mentioning the environment so we
> do not have to guess.
>
> /Str.
>
[toc] | [prev] | [next] | [standalone]
| From | Erwin Moller <erwinmollerusenet@xs4all.nl> |
|---|---|
| Date | 2012-01-26 16:18 +0100 |
| Message-ID | <4f216ebf$0$6951$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #4625 |
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@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.
>
> 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).
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.
Regards,
Erwin Moller
--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
[toc] | [prev] | [next] | [standalone]
| From | crankypuss <no@email.thanks> |
|---|---|
| Date | 2012-01-27 03:11 -0700 |
| Message-ID | <jftt8q0t84@news4.newsguy.com> |
| In reply to | #4627 |
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@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.
>>
>> 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.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-01-25 17:25 -0500 |
| Message-ID | <jfpvhi$p7h$1@dont-email.me> |
| In reply to | #4611 |
On 1/25/2012 2:47 PM, crankypuss wrote: > I'm sure there's a way to do this, probably some simple syntax I've not > run into and am too stupid to find in the manual or through google-fu or > otherwise. > > I'd like to issue an arbitrary shell command in a subroutine and have it > return an array that contains one element representing stdout and > another element representing stderr. > > For example, using tar to deal with a bazillion files, error messages > might not be seen when specifying verbose output; I'd like to collect > them and display after stdout. > > I've not found any syntax, yet, for redirecting to a PHP variable rather > than some file. > > tia. Take a look at the proc_open(). The examples show how do return stdout and stderr in separate streams. It may be more than you need (this is made to be interactive between the PHP script and the process), but you don't HAVE to send data to the process. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | crankypuss <no@email.thanks> |
|---|---|
| Date | 2012-01-27 03:16 -0700 |
| Message-ID | <jfttho0f5n@news3.newsguy.com> |
| In reply to | #4628 |
On 01/25/2012 03:25 PM, Jerry Stuckle wrote: > On 1/25/2012 2:47 PM, crankypuss wrote: >> I'm sure there's a way to do this, probably some simple syntax I've not >> run into and am too stupid to find in the manual or through google-fu or >> otherwise. >> >> I'd like to issue an arbitrary shell command in a subroutine and have it >> return an array that contains one element representing stdout and >> another element representing stderr. >> >> For example, using tar to deal with a bazillion files, error messages >> might not be seen when specifying verbose output; I'd like to collect >> them and display after stdout. >> >> I've not found any syntax, yet, for redirecting to a PHP variable rather >> than some file. >> >> tia. > > Take a look at the proc_open(). The examples show how do return stdout > and stderr in separate streams. Thanks Jerry, someone else mentioned that too, and it looks like it will probably do the trick though I'm not sure how soon I'll be able to play with it. > It may be more than you need (this is made to be interactive between the > PHP script and the process), but you don't HAVE to send data to the > process. I've never minded putting large amounts of effort into building something with a simple general purpose interface, those efforts tend to repay tenfold. (On a personal note, haven't you retired yet? Or are you like me, addicted to code for life?)
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-01-27 08:49 -0500 |
| Message-ID | <jfua0n$qii$1@dont-email.me> |
| In reply to | #4634 |
On 1/27/2012 5:16 AM, crankypuss wrote: > On 01/25/2012 03:25 PM, Jerry Stuckle wrote: >> On 1/25/2012 2:47 PM, crankypuss wrote: >>> I'm sure there's a way to do this, probably some simple syntax I've not >>> run into and am too stupid to find in the manual or through google-fu or >>> otherwise. >>> >>> I'd like to issue an arbitrary shell command in a subroutine and have it >>> return an array that contains one element representing stdout and >>> another element representing stderr. >>> >>> For example, using tar to deal with a bazillion files, error messages >>> might not be seen when specifying verbose output; I'd like to collect >>> them and display after stdout. >>> >>> I've not found any syntax, yet, for redirecting to a PHP variable rather >>> than some file. >>> >>> tia. >> >> Take a look at the proc_open(). The examples show how do return stdout >> and stderr in separate streams. > > Thanks Jerry, someone else mentioned that too, and it looks like it will > probably do the trick though I'm not sure how soon I'll be able to play > with it. > >> It may be more than you need (this is made to be interactive between the >> PHP script and the process), but you don't HAVE to send data to the >> process. > > I've never minded putting large amounts of effort into building > something with a simple general purpose interface, those efforts tend to > repay tenfold. > > (On a personal note, haven't you retired yet? Or are you like me, > addicted to code for life?) Nope, still too young to retire. I don't know what I'd do with myself :) -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.php
csiph-web