aboutsummaryrefslogtreecommitdiffstats
path: root/golib/eows/eows-out.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-02-23 17:40:32 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-02-23 17:40:32 +0100
commitabbf89a5589f2c92f786bb45c5cd613a318a9e24 (patch)
treed5b6f28e0b96570ee1486061057ac89de8f1f0d4 /golib/eows/eows-out.go
parent60e342228ba8017e1cacc71a64280143832e7719 (diff)
Add PtsMode support to eows libv0.2.0
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'golib/eows/eows-out.go')
-rw-r--r--golib/eows/eows-out.go26
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())
}