我的 go 语言程序打印“选项 -n 1 的错误值,有效范围是从 1 到 4294967295。”尝试使用以下代码片段进行 ping 操作时
result , err := exec.Command("ping","-n 1", "-w 1", ip).Output()
fmt.Printf("%s\n", result)
在 Win 中从 cmd 执行时,即“ping -n 1 -w 1 8.8.8.8”很好
最佳答案
您需要将 -n
和 -w
标志及其值分隔成单独的参数(您的 shell 已经这样做了):
result , err := exec.Command("ping", "-n", "1", "-w", "1", ip).Output()
关于go - exec.Command 输出中的 "Bad value ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40029713/