Skip to content

Instantly share code, notes, and snippets.

@keroloswilliam
Created August 15, 2019 11:28
Show Gist options
  • Save keroloswilliam/7e0ed138e22f3bf0880f1946f4caa6b2 to your computer and use it in GitHub Desktop.
Save keroloswilliam/7e0ed138e22f3bf0880f1946f4caa6b2 to your computer and use it in GitHub Desktop.
this is an example of using exec.LookPath with exec.Command in golang
package main
import (
"os/exec"
"fmt"
)
func main() {
if someBin, err := exec.LookPath("ls"); err != nil {
fmt.Println("couldn't find the ls bin in the path")
}else if err == nil {
actualBin := exec.Command(someBin, "-lah")
if stdout, err := actualBin.CombinedOutput(); err != nil {
fmt.Println(err)
}else if err == nil {
fmt.Println(string(stdout))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment