mirror of
https://github.com/wahyd4/forego.git
synced 2026-08-09 05:07:05 +10:00
fix long stdout read issue
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user