我需要获取类似whois '-i origin XXX' | grep ..."
这样的查询的输出,并将其保存在go中的变量中。我该怎么做?我应该通过go在系统上运行命令,还是可以使用任何Web API?
答案 0 :(得分:0)
您可以在Go中使用os/exec
软件包。这将需要一些参数,它将运行系统命令。
示例:
cmd := exec.Command(appname, arg0, arg1, arg2, arg3) //cmd should be in path variable
stdout, err := cmd.Output() //Running command
if err != nil {
fmt.Println(err.Error()) // If error come it will print it
return
}
fmt.Print(string(stdout)) // Printing the output of the command.
作为参考,请检查-> https://golang.org/pkg/os/exec/