0

I am running a command as such:

exec("grunt build --target=prod", $output, $status);

This just runs grunt within a folder and builds it. The output is captured without issue. However, it's all dumped at the end and grunt builds can take a bit to happen.

I'd like to know if I can capture the output as it happens and be able to echo it out in real time.

Any idea if that's a thing?

Gurnzbot
  • 3,742
  • 7
  • 36
  • 55

1 Answers1

0

You should use system() instead so you can capture the output of the command you've run...

If you assign the call to a variable you'll get the last line of the output, you'll also get the entire output, see:

$lastLine = system("grunt build --target=prod", $output);
print_r($output); // to get entire output

Along with output_buffering you can flush the output one line at a time.

Stuart
  • 6,630
  • 2
  • 24
  • 40