开发者

How do I pipe rake output using php?

I'm building a RAKEFILE and I want to display the output on a php generated page as it gets executed.

I tried using system() since the PHP docs mention this:

The system() call also tries to automatically flush the web server's o开发者_如何学JAVAutput buffer after each line of output if PHP is running as a server module.

This seems to work with multiple shell comands but when I execute rake I only get the first line:

(in /Users/path/to/proj)

Any ideas?

Cheers!


Try use exec() function

   exec($command, $output); 

$output is an array

//retrieved data
for($out = '',$x = 0,$len = count($output); $x < $len; $x++) {
      $out .= $output[$x] . "\r\n";
}

or simple:

$out = join("\r\n", $output); 


The system() call also tries to automatically flush the web server's output buffer after > each line of output if PHP is running as a server module.

This means you would only get the last line of output from the return value. The example in the system() manual page shows that and it suggests to use passthru() to get raw output. I usually use exec() though.


Turs out both functions system() & exec() actually work. The generated rake output when using --verbose isn't taken into consideration though. That's why I was confused. If anyone has more extensive knowledge on the distinction, do share :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜