Created
January 4, 2019 16:58
-
-
Save pascal08/2c6b017db37d9956a3152f431bec473e to your computer and use it in GitHub Desktop.
Execute shell command
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
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