add total byte counts to track accurate flushing of buffers

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-09 23:48:53 +00:00
parent 026c59bc5c
commit f1d7a816be
1 changed files with 29 additions and 12 deletions

View File

@ -72,12 +72,17 @@ func Run(cmdline string) int {
newerrreader := bufio.NewReader(pstderr)
nbrerr := nbreader.NewNBReader(newerrreader, 1024)
totalCount := 0
for {
time.Sleep(2 * time.Millisecond) // only check the buffer 500 times a second
// log.Println("sleep done")
// tight loop that reads 1K at a time until buffer is empty
for {
oneByte := make([]byte, 1024)
count, err := nbr.Read(oneByte)
totalCount += count
if (err != nil) {
// log.Println("Read() count = ", count, "err = ", err)
@ -88,9 +93,21 @@ func Run(cmdline string) int {
}
f.Write([]byte(string(oneByte)))
f.Flush()
if (count == 0) {
break
}
}
oneByte = make([]byte, 1024)
count, err = nbrerr.Read(oneByte)
if (totalCount != 0) {
log.Println("totalCount = ", totalCount)
}
//
// HANDLE STDERR
// HANDLE STDERR
//
oneByte := make([]byte, 1024)
count, err := nbrerr.Read(oneByte)
if (err != nil) {
oneByte = make([]byte, 1024)
@ -99,8 +116,8 @@ func Run(cmdline string) int {
f.Flush()
log.Println("Read() count = ", count, "err = ", err)
spew.Dump(process.Process)
spew.Dump(process.ProcessState)
// spew.Dump(process.Process)
// spew.Dump(process.ProcessState)
err := process.Wait()
if err != nil {
spew.Dump(err.(*exec.ExitError))