[go-nuts] idiomatic code to find, if executable exists in golang

2018-09-26 Thread Dave Cheney
Are you able to modify the original question. Why do you need to know if a 
binary exists? Presumably so you can execute it. If so then you can modify the 
original request and make the problem more tractable. 

-- 
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.


[go-nuts] idiomatic code to find, if executable exists in golang

2018-09-25 Thread Nilsocket
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.