Skip to content

Instantly share code, notes, and snippets.

@pcgeek86
Created August 26, 2022 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcgeek86/54ac7bd70db636bab5f20094f62f3e4e to your computer and use it in GitHub Desktop.
Save pcgeek86/54ac7bd70db636bab5f20094f62f3e4e to your computer and use it in GitHub Desktop.
Run External Command in Golang
package main
import (
"fmt"
"os/exec"
)
func main() {
// NOTE: mycmd will contain a byte array, not string output
mycmd, _ := exec.Command("ls", "-lGa", "/").Output()
// Convert mycmd byte array to string, and print to terminal
fmt.Println(string(mycmd))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment