程序如下,报错了,为什么呢?
```go
package main
import (
"fmt"
"os/exec"
)
func main() {
cmd := exec.Command("ping", "127.0.0.1", "-c 1 -W 1")
out, err := cmd.Output()
if err != nil {
fmt.Println("Command Error!", err.Error())
} else {
fmt.Println(out)
}
}
```
代码:
```go
package main
import (
"fmt"
"os/exec"
)
func main() {
cmd := exec.Command("ping", "-c 1 -W 1", "127.0.0.1")
out, err := cmd.Output()
if err != nil {
fmt.Printf("Command Error", err.Error())
} else {
fmt.Printf("%s\n", out)
}
}
```
#2
更多评论
改成这样
exec.Command("ping", "-c 1", "-W 1", "127.0.0.1")
#1