outputting external proc to both pipe and php://stdout

102 Views Asked by At

If I run an external script in PHP using

$p = proc_open(
    'myscript.php', 
    array(
        0 => array('file', 'inputfile.txt', 'r'),
        1 => array('pipe', 'w'),
        2 => array('pipe', 'w'),
    ), 
    $pipes,
    $path
);

then I am able to get the stderr output via

$error = stream_get_contents($pipes[2]);

If I want to have the stderr output displayed on the console, then I can have it run as:

$p = proc_open(
    'myscript.php', 
    array(
        0 => array('file', 'inputfile.txt', 'r'),
        1 => array('file', 'php://stdout', 'w'),
        2 => array('file', 'php://stderr', 'w'),
    ), 
    $pipes,
    $path
);

However,

$error = stream_get_contents($pipes[2]);

will not produce any output.

How do I have the stderr output both print to the console and be available for use by my script?

0

There are 0 best solutions below