Created
April 27, 2017 21:48
-
-
Save gesquive/4315ace7864c5507e3dc6ff249edc3c6 to your computer and use it in GitHub Desktop.
Run an external command with golang
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
// run a command using the shell; no need to split args | |
// from https://stackoverflow.com/questions/6182369/exec-a-shell-command-in-go | |
func runcmd(cmd string, shell bool) []byte { | |
if shell { | |
out, err := exec.Command("bash", "-c", cmd).Output() | |
if err != nil { | |
log.Fatal(err) | |
panic("some error found") | |
} | |
return out | |
} | |
out, err := exec.Command(cmd).Output() | |
if err != nil { | |
log.Fatal(err) | |
} | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment