Created
August 15, 2019 11:28
-
-
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
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
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