Created
November 18, 2014 09:29
-
-
Save rjeczalik/113d1dd2b5b29e4c1452 to your computer and use it in GitHub Desktop.
go-exec: debugging os/exec with interactive scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"os/exec" | |
) | |
func die(v interface{}) { | |
fmt.Fprintln(os.Stderr, v) | |
os.Exit(1) | |
} | |
func main() { | |
if len(os.Args) == 1 { | |
die("usage: go-exec COMMAND [ARG...]") | |
} | |
cmd := exec.Command(os.Args[1], os.Args[2:]...) | |
cmd.Stdout = os.Stdout | |
cmd.Stderr = os.Stderr | |
if err := cmd.Run(); err != nil { | |
die(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment