fix long stdout read issue

This commit is contained in:
Chungsub Kim
2014-07-08 21:44:02 +09:00
parent 73521422be
commit e3ec97bf7c
+21 -3
View File
@@ -7,6 +7,7 @@ import (
"io"
"os"
"sync"
"bytes"
)
type OutletFactory struct {
@@ -33,9 +34,26 @@ func (of *OutletFactory) LineReader(wg *sync.WaitGroup, name string, index int,
color := colors[index%len(colors)]
scanner := bufio.NewScanner(r)
for scanner.Scan() {
of.WriteLine(name, scanner.Text(), color, ct.None, isError)
reader := bufio.NewReader(r)
var buffer bytes.Buffer
for {
buf := make([]byte, 1024)
v, _ := reader.Read(buf)
if v == 0 {
return
}
idx := bytes.IndexByte(buf, '\n')
if idx >= 0 {
buffer.Write(buf[0:idx])
of.WriteLine(name, buffer.String(), color, ct.None, isError)
buffer.Reset()
} else {
buffer.Write(buf)
}
}
}