如何获取 proc_open() 的输出
我尝试从 php 中的 proc_open 方法获取输出,但是,当我打印它时,我得到了空。
$descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", "files/temp/error-output.txt", "a") ); $process = proc_open("time ./a a.out", $descriptorspec, $pipes, $cwd);
据我所知,我可以使用 stream_get_contents()
获得输出,
echo stream_get_contents($pipes[1]); fclose($pipes[1]);
但我不能这样做.. 有什么建议吗?
谢谢之前...
I've tried to get output from proc_open
method in php, but, when I print it, I got empty.
$descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", "files/temp/error-output.txt", "a") ); $process = proc_open("time ./a a.out", $descriptorspec, $pipes, $cwd);
as long as I know, I can get the output with stream_get_contents()
echo stream_get_contents($pipes[1]); fclose($pipes[1]);
But I can't do that..
any suggestion?
Thx before...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的代码或多或少对我有用。
time
将其输出打印到stderr
,因此如果您要查找该输出,请查看文件files/temp/error-output.txt
。stdout
管道$pipes[1]
将仅包含程序./a
的输出。我的重现:
Your code more or less works for me.
time
prints its output tostderr
so if you're looking for that output, look in your filefiles/temp/error-output.txt
. Thestdout
pipe$pipes[1]
will only contain the output of the program./a
.My repro:
这是
proc_open()
的另一个示例。我在本例中使用 Win32 ping.exe 命令。 CMIIW
希望这有帮助 =)
this is another example with
proc_open()
.I am using Win32 ping.exe command in this example. CMIIW
Hope this helps =)
这是读取 stdout 和 stderr 的完整函数。
Here is a complete functions which reads stdout and stderr.