Skip to content

Commit

Permalink
Simplify and fix input/output/err handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pcasaretto committed Jun 28, 2019
1 parent e7d5392 commit a9b9ccf
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -33,25 +32,16 @@ func main() {
if err != nil {
log.Fatalf("Error parsing file %s\n\t%s\n", *filename, err)
}
env = append(env, os.Environ()...)

cmdArgs := flag.Args()
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
stdinPipe, err := cmd.StdinPipe()
if err != nil {
log.Fatalf("Failed opening stdin")
}
go io.Copy(stdinPipe, os.Stdin)
stdoutPipe, err := cmd.StdoutPipe()
if err != nil {
log.Fatalf("Failed opening stdout")
}
go io.Copy(os.Stdout, stdoutPipe)
stderrPipe, err := cmd.StderrPipe()
if err != nil {
log.Fatalf("Failed opening stderr")
}
go io.Copy(os.Stderr, stderrPipe)
env = append(env, os.Environ()...)

cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

cmd.Env = env

cmd.Run()
}

0 comments on commit a9b9ccf

Please sign in to comment.