Skip to content

Commit

Permalink
Merge pull request #58 from dreid/dreid/simplify-subprocess-io-manage…
Browse files Browse the repository at this point in the history
…ment

Simplify subprocess IO management.
  • Loading branch information
Paul Osman authored Feb 25, 2020
2 parents 8e34042 + 457c006 commit 19db0e9
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions cmd_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"crypto/rand"
"fmt"
"io"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -91,26 +90,8 @@ func runCommand(subcmd string) error {
fmt.Println("running /bin/bash -c", subcmd)
cmd := exec.Command("/bin/bash", "-c", subcmd)

outReader, err := cmd.StdoutPipe()
if err != nil {
return err
}
errReader, err := cmd.StderrPipe()
if err != nil {
return err
}

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

go func() {
io.Copy(os.Stdout, outReader)
}()
go func() {
io.Copy(os.Stderr, errReader)
}()
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

return cmd.Wait()
return cmd.Run()
}

0 comments on commit 19db0e9

Please sign in to comment.