gpt4 book ai didi

go - 执行系统命令的最佳方式是什么

转载 作者:行者123 更新时间:2023-12-01 22:45:47 25 4
gpt4 key购买 nike

关闭。这个问题需要debugging details .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

2年前关闭。




Improve this question




我需要得到这样的查询的输出 whois '-i origin XXX' | grep ..."并将其保存在变量中。我该怎么做?我应该通过 go 在系统上运行命令还是有任何 web api 可以用来执行此操作?

最佳答案

您可以使用 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/

关于go - 执行系统命令的最佳方式是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60506197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com