Re: redirect stdout and stderr to PHP variables? [message #176801 is a reply to message #176799] |
Wed, 25 January 2012 21:46 |
M. Strobel
Messages: 386 Registered: December 2011
Karma:
|
Senior Member |
|
|
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.
|
|
|