1

First.. my php knowledge are very poor.

The target is to display the live content of an bash script via a web page. The bash script itself as three tasks:

  1. prepare data
  2. some infos to the user
  3. execute a bin file

All works... but the displayed content is not what i expect. more precisely: the chronological sequence

The bin file produce a large amount of unneeded information. So i use grep and sed to filter the content:

If i dont filter with "grep" and "sed"... the output is live.

If i use "grep" and "sed".... the output of the bin file is only after the execution displayed.

Timecode 0s: Hello
Timecode 17:  Generating Baseline: 1/9  4000/4000 6.586
Timecode 17:  Generating Agi: 2/9  4000/4000 6.563
Timecode 17: Generating AP: 3/9  4000/4000 6.567

that's how the output should be:

Timecode 0s: Hello
Timecode 4:  Generating Baseline: 1/9  4000/4000 6.586
Timecode 6:  Generating Agi: 2/9  4000/4000 6.563
Timecode 10: Generating AP: 3/9  4000/4000 6.56

Why? How i can solve this problem... filter the output of "simc" and forward the output live?

The code:

bash script part:

#!/bin/bash
echo "Hello"
simc $PLAYER $COMMAND html=/tmp/report_manual.html | grep --line-buffered "Generating" | sed 's/\[.*\]//g'

exit
  • also tested without "--line-buffered"

php script part:

<?php
ob_end_flush();
ob_implicit_flush();

$char_name = $_POST["char_name"];

$cmd = "bash /home/nas/script/simc/webclient.sh {$char_name} 2>&1";

while (@ ob_end_flush()); // end all output buffers if any
        $proc = popen($cmd ,'r');
        echo '<pre>';
while (!feof($proc))
{
        echo fread($proc, 2098);
        @ flush();
}
echo '</pre>';
?>

EDIT: PHP reading shell_exec live output did not cover my question.

Christian
  • 11
  • 3

0 Answers0