aboutsummaryrefslogtreecommitdiffstats
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.go49
1 files changed, 37 insertions, 12 deletions
diff --git a/golib/eows/eows-out.go b/golib/eows/eows-out.go
index 2d9bdb0..3163b2f 100644
--- a/golib/eows/eows-out.go
+++ b/golib/eows/eows-out.go
@@ -56,16 +56,15 @@ func (e *ExecOverWS) _pumper(sc *bufio.Scanner, fctCB func(s string)) {
}
-// cmdPumpStdout is in charge to forward stdout in websocket
-func (e *ExecOverWS) cmdPumpStdout(r io.Reader, done chan struct{}) {
-
- defer func() {
- }()
+// pipePumpStdout is in charge to forward stdout in websocket
+func (e *ExecOverWS) pipePumpStdout(r io.Reader, done chan struct{}) {
sc := bufio.NewScanner(r)
e._pumper(sc, func(b string) {
- e.OutputCB(e, b, "")
+ if e.OutputCB != nil {
+ e.OutputCB(e, []byte(b), []byte{})
+ }
})
e.logDebug("STDOUT pump exit")
@@ -77,16 +76,15 @@ func (e *ExecOverWS) cmdPumpStdout(r io.Reader, done chan struct{}) {
close(done)
}
-// cmdPumpStderr is in charge to forward stderr in websocket
-func (e *ExecOverWS) cmdPumpStderr(r io.Reader) {
-
- defer func() {
- }()
+// pipePumpStderr is in charge to forward stderr in websocket
+func (e *ExecOverWS) pipePumpStderr(r io.Reader) {
sc := bufio.NewScanner(r)
e._pumper(sc, func(b string) {
- e.OutputCB(e, "", b)
+ if e.OutputCB != nil {
+ e.OutputCB(e, []byte{}, []byte(b))
+ }
})
e.logDebug("STDERR pump exit")
@@ -95,3 +93,30 @@ func (e *ExecOverWS) cmdPumpStderr(r io.Reader) {
e.logError("stderr scan: %v", sc.Err())
}
}
+
+// ptsPumpStdout is in charge to forward stdout in websocket
+// (only used when PtyMode is set)
+func (e *ExecOverWS) ptsPumpStdout(r io.Reader, done chan struct{}) {
+
+ buffer := make([]byte, 1024)
+ for {
+ n, err := r.Read(buffer)
+ if err != nil {
+ if err != io.EOF &&
+ !strings.Contains(err.Error(), "file already closed") {
+ e.logError("Error stdout read: %v", err)
+ }
+ break
+ }
+ if n == 0 {
+ continue
+ }
+ if e.OutputCB != nil {
+ e.OutputCB(e, buffer[:n], []byte{})
+ }
+ }
+
+ close(done)
+
+ e.logDebug("Eows stdout pump exited")
+}