如何从由popen在php中打开的进程中获取输出? [英] how get the output from process opend by popen in php?

查看:479
本文介绍了如何从由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中打开的进程中获取输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆