Skip to content

Instantly share code, notes, and snippets.

@pascal08
Created January 4, 2019 16:58
Show Gist options
  • Save pascal08/2c6b017db37d9956a3152f431bec473e to your computer and use it in GitHub Desktop.
Save pascal08/2c6b017db37d9956a3152f431bec473e to your computer and use it in GitHub Desktop.
Execute shell command
package main
import (
"fmt"
"log"
"os/exec"
)
func main() {
binary, lookErr := exec.LookPath("bash")
if lookErr != nil {
panic(lookErr)
}
cmd := exec.Command(binary, "-c", "ls -la")
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
fmt.Printf("combined out:\n%s\n", string(out))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment