file a.php:
<?php
echo "abcdef";
?>
file b.php:
<?php
$h=popen('php a.php',r);
pclose($h);
?>
question:
I can't see the echo result on console; why and how to see it?
I don't want to do it in file b.php like:echo stream_get_contents($h);
Check the second example in the documentation on popen, it shows exactly how to do that:
<?php
error_reporting(E_ALL);
/* Add redirection so we can get stderr. */
$handle = popen('/path/to/executable 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);
This snippet reads from stderr. Remove the pipe to read from stdout.