Bob*_*nly 11 php linux proc-open
我试图从proc_open
php中获取方法的输出,但是,当我打印它时,我变空了.
$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]);
但我不能这样做......有什么建议吗?
先谢谢......
您的代码或多或少对我有用. time
打印输出,stderr
如果您正在寻找输出,请查看您的文件files/temp/error-output.txt
.该stdout
管道$pipes[1]
将只包含该程序的输出./a
.
我的责备:
[edan@edan tmp]$ cat proc.php
<?php
$cwd='/tmp';
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "/tmp/error-output.txt", "a") );
$process = proc_open("time ./a a.out", $descriptorspec, $pipes, $cwd);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
?>
[edan@edan tmp]$ php proc.php
a.out here.
[edan@edan tmp]$ cat /tmp/error-output.txt
real 0m0.001s
user 0m0.000s
sys 0m0.002s
Run Code Online (Sandbox Code Playgroud)
这是另一个例子proc_open()
.我在这个例子中使用Win32 ping.exe命令.CMIIW
set_time_limit(1800);
ob_implicit_flush(true);
$exe_command = 'C:\\Windows\\System32\\ping.exe -t google.com';
$descriptorspec = array(
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout -> we use this
2 => array("pipe", "w") // stderr
);
$process = proc_open($exe_command, $descriptorspec, $pipes);
if (is_resource($process))
{
while( ! feof($pipes[1]))
{
$return_message = fgets($pipes[1], 1024);
if (strlen($return_message) == 0) break;
echo $return_message.'<br />';
ob_flush();
flush();
}
}
Run Code Online (Sandbox Code Playgroud)
希望这有助于=)
归档时间: |
|
查看次数: |
21487 次 |
最近记录: |