Skip to content

Commit 0799138

Browse files
committed
[#390] Simplify toolchain capture of command stderr and stdout
1 parent 1816015 commit 0799138

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/toolchain/command_runner.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ package toolchain
2525
import (
2626
"bufio"
2727
"github.com/murex/tcr/report"
28+
"io"
2829
"os/exec"
2930
)
3031

@@ -83,9 +84,8 @@ func (r *CommandRunner) Run(cmd *Command) (result CommandResult) {
8384
// Allow simultaneous trace and capture of command's stdout and stderr
8485
outReader, _ := r.command.StdoutPipe()
8586
errReader, _ := r.command.StderrPipe()
86-
doneOut, doneErr := make(chan bool), make(chan bool)
87-
r.reportCommandTrace(bufio.NewScanner(outReader), doneOut)
88-
r.reportCommandTrace(bufio.NewScanner(errReader), doneErr)
87+
r.reportCommandTrace(outReader)
88+
r.reportCommandTrace(errReader)
8989

9090
// Start the command asynchronously
9191
errStart := r.command.Start()
@@ -113,11 +113,11 @@ func (r *CommandRunner) Run(cmd *Command) (result CommandResult) {
113113
return result
114114
}
115115

116-
func (*CommandRunner) reportCommandTrace(scanner *bufio.Scanner, done chan bool) {
116+
func (*CommandRunner) reportCommandTrace(readCloser io.ReadCloser) {
117+
scanner := bufio.NewScanner(readCloser)
117118
go func() {
118119
for scanner.Scan() {
119120
report.PostText(scanner.Text())
120121
}
121-
done <- true
122122
}()
123123
}

0 commit comments

Comments
 (0)