本文介绍了如何从由popen在php中打开的进程中获取输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
文件a.php:
<?php echo "abcdef"; ?>文件b.php:
<?php $h=popen('php a.php',r); pclose($h); ?>问题:
我无法在控制台上看到回显结果; 为什么以及如何看到它?
I can't see the echo result on console; why and how to see it?
我不想在文件b.php中这样做,例如:echo stream_get_contents($h);
I don't want to do it in file b.php like:echo stream_get_contents($h);
推荐答案在 popen ,它确切地说明了如何做到这一点:
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);此代码段从stderr中读取.删除要从stdout读取的管道.
This snippet reads from stderr. Remove the pipe to read from stdout.
更多推荐
如何从由popen在php中打开的进程中获取输出?
发布评论