If you wish to capture terminal output of a command as it progresses, you can use example below. It will run given command, capture original output and reprint line by line. If you want, you can manipulate the line before printing it.


Example


package main

import (
"bufio"
"fmt"
"io"
"log"
"os/exec"
)

func main() {
cmd := exec.Command("gotest", "-v", "./...")

stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}

err = cmd.Start()
if err != nil {
log.Fatal(err)
}

buffer := bufio.NewReader(stdout)

for {
line, _, err := buffer.ReadLine()

fmt.Println(string(line))

if err == io.EOF {
break
}
}
}