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]);
しかし、私はそれを行うことはできません。
前のTHX ...
あなたのコードは多かれ少なかれ私にとってはうまくいきます。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
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加