I have this app that needs to ping google.com to see if the network connection is alive.
The following works code fine and lists the directory content:
cmd = exec.Command("ls", "-lah")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err = cmd.Run()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
fmt.Printf("out:\n%s\nerr:\n%s\n", outStr, errStr)
When I change the args this hangs.
cmd = exec.Command("ping", "goole.com")
This causes an error: cmd.Run() failed with exit status 2
cmd = exec.Command("ping", "https://www.goole.com")
After i changed the args to:
cmd = exec.Command("ping -c 5", "goole.com")
I get
cmd.Run() failed with exec: "ping -c 5": executable file not found in $PATH
I'm using go mod for my dependencies. Any idea what I do wrong?