summaryrefslogtreecommitdiffstats
path: root/golib/eows/eows-out.go
diff options
context:
space:
mode:
Diffstat (limited to 'golib/eows/eows-out.go')
-rw-r--r--golib/eows/eows-out.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/golib/eows/eows-out.go b/golib/eows/eows-out.go
new file mode 100644
index 0000000..d624618
--- /dev/null
+++ b/golib/eows/eows-out.go
@@ -0,0 +1,47 @@
+package eows
+
+import (
+ "bufio"
+ "io"
+)
+
+// scanBlocks
+func scanBlocks(data []byte, atEOF bool) (advance int, token []byte, err error) {
+ if atEOF && len(data) == 0 {
+ return 0, nil, nil
+ }
+ return len(data), data, nil
+}
+
+// cmdPumpStdout is in charge to forward stdout in websocket
+func (e *ExecOverWS) cmdPumpStdout(r io.Reader, done chan struct{}) {
+
+ defer func() {
+ }()
+
+ sc := bufio.NewScanner(r)
+ sc.Split(scanBlocks)
+ for sc.Scan() {
+ e.OutputCB(e, sc.Text(), "")
+ }
+ if sc.Err() != nil {
+ e.logError("stdout scan:", sc.Err())
+ }
+
+ close(done)
+}
+
+// cmdPumpStderr is in charge to forward stderr in websocket
+func (e *ExecOverWS) cmdPumpStderr(r io.Reader) {
+
+ defer func() {
+ }()
+ sc := bufio.NewScanner(r)
+ sc.Split(scanBlocks)
+ for sc.Scan() {
+ e.OutputCB(e, "", sc.Text())
+ }
+ if sc.Err() != nil {
+ e.logError("stderr scan:", sc.Err())
+ }
+}