如何从由popen在php中打开的进程中获取输出?

编程入门 行业动态 更新时间:2024-10-15 02:29:32
本文介绍了如何从由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中打开的进程中获取输出?

本文发布于:2023-08-05 02:05:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1301646.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   popen   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!