package main
import (
"os"
"os/exec"
)
func main() {
cmdName := os.Args[1]
//either cmd or executable without arguments
if _, err := exec.LookPath(cmdName); err != nil {
if (err.(*exec.Error)).Err == exec.ErrNotFound {
// executable doesn't exist, do something
} else {
// error, may be related to permissions
}
} else {
// executable exists, do something
}
}
Is this the only way to know if executable exists?
Is there any other function which does the same thing in stdlib.
Is there any other better way to do this?
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.