summaryrefslogtreecommitdiffstats
path: root/golib/eows/eows-out.go
blob: d624618229ed1a68c3d0776affc607a538235cec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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())
	}
}