golang中os/exec包用法
2016-11-25 17:36
309 查看
exec包执行外部命令,它将os.StartProcess进行包装使得它更容易映射到stdin和stdout,并且利用pipe连接i/o.
1.func LookPath(file string) (string, error)
在环境变量PATH指定的目录中搜索可执行文件,如file中有斜杠,则只在当前目录搜索。返回完整路径或者相对于当前目录的一个相对路径。
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
相关文章推荐
- golang中os/exec包用法
- golang中os/exec包用法
- golang中os/exec包用法
- golang中os/exec包用法
- golang 返回字符串格式化及fm用法
- golang 中unicode包用法
- Golang中的sync.WaitGroup用法实例
- golang中image/color包的用法
- golang时间相关的用法总结
- Golang 1.7.3 Context 简单用法.类似sync.WaitGroup
- golang的defer,recover,panic用法
- golang中net包用法
- golang 中unicode包用法
- golang中os/user包用法
- golang守护进程用法示例
- Golang channel用法
- Golang JSON的进阶用法实例讲解
- Golang的循环中break和continue语句的用法讲解
- golang 中 锁的错误的用法会导致死锁。
- golang 中的多态用法