go - golang: cmd.Exec(): How I can read non-buffered stdout of apps? -
so have simple app starts other apps , reads 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() { log.printf("....") time.sleep(1 * time.second) l, _ := in.readstring('\n') log.printf(string(l)) } }
the point of real app read output of running process , parse it.. doesn't works real apps don't explicitly sync/flush stdout (it takes ~60 lines of iperf
output before starting printing).
what efficient way read output byte-by-byte?
Comments
Post a Comment