When I'm looking at the source of the exec.Command()
it doesnt return an error but only returns Cmd
which is struct in the package exe
:
source
....
func Command(name string, arg ...string) *Cmd {
cmd := &Cmd{
Path: name,
Args: append([]string{name}, arg...),
}
if filepath.Base(name) == name {
if lp, err := LookPath(name); err != nil {
cmd.lookPathErr = err
} else {
cmd.Path = lp
}
}
return cmd
}
....
I have succesfully got the binary file running using this code :
package main
import (
"fmt"
"os/exec"
)
func main() {
command:= exec.Command("Your binary file path")
// set var to get the output
var out bytes.Buffer
// set the output to our variable
command.Stdout = &out
err = command.Run()
if err != nil {
log.Println(err)
}
fmt.Println(out.String())
}
This one works for me for running a binary file that will print some random string.