So I have the simple app which starts other apps and reads their output.
package main
import (
"bufio"
"io"
"log"
"os/exec"
"time"
)
func main() {
cmd := exec.Command("perl", "-e", "my $x = 0; while (1) { print ++$x.qx'date'; sleep 1; }")
stdout, _ := cmd.StdoutPipe()
stderr, _ := cmd.StderrPipe()
in := bufio.NewReaderSize(io.MultiReader(stdout, stderr), 100)
cmd.Start()
defer cmd.Wait()
for {
log.Printf("....")
time.Sleep(1 * time.Second)
l, _ := in.ReadString('
')
log.Printf(string(l))
}
}
The point of the real app is to read output of running process and parse it.. however it doesn't works well with real apps which don't explicitly sync/flush their stdout (it takes ~60 lines of iperf
output before starting printing).
What is the most efficient way to read output byte-by-byte?