Skip to content

Instantly share code, notes, and snippets.

@ae6rt
Created November 16, 2014 14:48
Show Gist options
  • Save ae6rt/2c17d65bed574c895f0e to your computer and use it in GitHub Desktop.
Save ae6rt/2c17d65bed574c895f0e to your computer and use it in GitHub Desktop.
Wrapper around Go exec.Command to return stdout, stderr, and err
func Exec(cmd string, args ...string) ([]byte, []byte, error) {
if debug {
log.Printf("%s %v\n", cmd, args)
}
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
command := exec.Command(cmd, args...)
command.Stdout = stdout
command.Stderr = stderr
err := command.Run()
return stdout.Bytes(), stderr.Bytes(), err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment