package executor import ( "bufio" "fmt" "io" "os/exec" ) func ReadTimeCommandExecutor(singleLineCommand []string) { cmd := exec.Command(singleLineCommand[0], singleLineCommand[1:]...) stdout, err := cmd.StdoutPipe() if err != nil { log.ErrorF("command %v stdout error => %v", singleLineCommand, err) } stderr, err := cmd.StderrPipe() if err != nil { log.ErrorF("command %v stderr error => %v", singleLineCommand, err) } if err := cmd.Start(); err != nil { log.ErrorF("command %v runtime error => %v", singleLineCommand, err) } go copyOutput(stdout) go copyOutput(stderr) if err := cmd.Wait(); err != nil { log.ErrorF("command %v result error => %v", singleLineCommand, err) } } func copyOutput(r io.Reader) { scanner := bufio.NewScanner(r) for scanner.Scan() { fmt.Println(scanner.Text()) } }