Created
November 16, 2014 14:48
-
-
Save ae6rt/2c17d65bed574c895f0e to your computer and use it in GitHub Desktop.
Wrapper around Go exec.Command to return stdout, stderr, and err
This file contains hidden or 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
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