feat: split stdout and stderr reader, writer
parent
64ebde9ef8
commit
421efc5422
30
main.go
30
main.go
|
@ -24,16 +24,19 @@ func runGoTest() int {
|
||||||
cmd := exec.Command("go", args...)
|
cmd := exec.Command("go", args...)
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
|
|
||||||
reader, writer := io.Pipe()
|
outReader, outWriter := io.Pipe()
|
||||||
defer writer.Close()
|
defer outWriter.Close()
|
||||||
|
|
||||||
cmd.Stdout = writer
|
errReader, errWriter := io.Pipe()
|
||||||
cmd.Stderr = writer
|
defer errWriter.Close()
|
||||||
|
|
||||||
|
cmd.Stdout = outWriter
|
||||||
|
cmd.Stderr = errWriter
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer reader.Close()
|
defer outReader.Close()
|
||||||
|
|
||||||
scanner := bufio.NewScanner(reader)
|
scanner := bufio.NewScanner(outReader)
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
|
@ -60,6 +63,21 @@ func runGoTest() int {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer errReader.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(errReader)
|
||||||
|
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
color.Red("%s\n", line)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
log.Printf("scanner error: %s", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue