diff --git a/runner/engine.go b/runner/engine.go index 7af4ed18..9c73a614 100644 --- a/runner/engine.go +++ b/runner/engine.go @@ -434,14 +434,12 @@ func (e *Engine) runCommand(command string) error { stdout.Close() stderr.Close() }() - _, _ = io.Copy(os.Stdout, stdout) - _, _ = io.Copy(os.Stderr, stderr) + + copyOutput(os.Stdout, stdout) + copyOutput(os.Stderr, stderr) + // wait for command to finish - err = cmd.Wait() - if err != nil { - return err - } - return nil + return cmd.Wait() } // run cmd option in .air.toml @@ -551,15 +549,9 @@ func (e *Engine) runBin() error { go killFunc(cmd, stdout, stderr, killCh, processExit) }) - go func() { - _, _ = io.Copy(os.Stdout, stdout) - _, _ = cmd.Process.Wait() - }() + go copyOutput(os.Stdout, stdout) + go copyOutput(os.Stderr, stderr) - go func() { - _, _ = io.Copy(os.Stderr, stderr) - _, _ = cmd.Process.Wait() - }() state, _ := cmd.Process.Wait() close(processExit) switch state.ExitCode() { diff --git a/runner/util.go b/runner/util.go index 80a71265..932c60b5 100644 --- a/runner/util.go +++ b/runner/util.go @@ -1,9 +1,11 @@ package runner import ( + "bufio" "crypto/sha256" "encoding/hex" "errors" + "io" "log" "os" "path/filepath" @@ -206,6 +208,13 @@ func (e *Engine) logWithLock(f func()) { e.ll.Unlock() } +func copyOutput(dst io.Writer, src io.Reader) { + scanner := bufio.NewScanner(src) + for scanner.Scan() { + dst.Write([]byte(scanner.Text() + "\n")) + } +} + func expandPath(path string) (string, error) { if strings.HasPrefix(path, "~/") { home := os.Getenv("HOME")