diff options
Diffstat (limited to 'golib/eows/eows-out.go')
-rw-r--r-- | golib/eows/eows-out.go | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/golib/eows/eows-out.go b/golib/eows/eows-out.go index b70e70c..2d9bdb0 100644 --- a/golib/eows/eows-out.go +++ b/golib/eows/eows-out.go @@ -16,7 +16,7 @@ func scanChars(data []byte, atEOF bool) (advance int, token []byte, err error) { } // _pumper is in charge to collect -func (e *ExecOverWS) _pumper(sc *bufio.Scanner, fctOut func(s string)) { +func (e *ExecOverWS) _pumper(sc *bufio.Scanner, fctCB func(s string)) { // Select split function (default sc.ScanLines) if e.OutSplit == SplitChar || e.OutSplit == SplitLineTime || e.OutSplit == SplitTime { @@ -31,20 +31,26 @@ func (e *ExecOverWS) _pumper(sc *bufio.Scanner, fctOut func(s string)) { buf += sc.Text() if time.Since(t0).Nanoseconds() > e.LineTimeSpan || (e.OutSplit == SplitLineTime && strings.Contains(buf, "\n")) { - fctOut(buf) + fctCB(buf) buf = "" t0 = time.Now() } + if e.procExited { + break + } } // Send remaining characters if len(buf) > 0 { - e.OutputCB(e, "", buf) + fctCB(buf) } } else { for sc.Scan() { - e.OutputCB(e, sc.Text(), "") + fctCB(sc.Text()) + if e.procExited { + break + } } } @@ -58,10 +64,12 @@ func (e *ExecOverWS) cmdPumpStdout(r io.Reader, done chan struct{}) { sc := bufio.NewScanner(r) - e._pumper(sc, func(bufOut string) { - e.OutputCB(e, bufOut, "") + e._pumper(sc, func(b string) { + e.OutputCB(e, b, "") }) + e.logDebug("STDOUT pump exit") + if sc.Err() != nil && !strings.Contains(sc.Err().Error(), "file already closed") { e.logError("stdout scan: %v", sc.Err()) } @@ -77,10 +85,12 @@ func (e *ExecOverWS) cmdPumpStderr(r io.Reader) { sc := bufio.NewScanner(r) - e._pumper(sc, func(bufErr string) { - e.OutputCB(e, "", bufErr) + e._pumper(sc, func(b string) { + e.OutputCB(e, "", b) }) + e.logDebug("STDERR pump exit") + if sc.Err() != nil && !strings.Contains(sc.Err().Error(), "file already closed") { e.logError("stderr scan: %v", sc.Err()) } |