golang中os/exec包用法
exec包执行外部命令,它将os.StartProcess进行包装使得它更容易映射到stdin和stdout,并且利用pipe连接i/o. 1.func LookPath(file string) (string, error) 在环境变量PATH指定的目录中搜索可执行文件,如file中有斜杠,则只在当前目录搜索。返回完整路径或者相对于当前目录的一个相对路径。 [root@myserver01 http]# vim os.go package main import( "os/exec" "fmt" "os" ) func main(){ f,err := exec.LookPath("yum") if err != nil{ fmt.Println(err) os.Exit(1) } fmt.Println(f) } [root@myserver01 http]# go build os.go [root@myserver01 http]# ./os /usr/bin/yum 来源: https://www.cnblogs.com/vijayfly/p/6102470.html