GO语言中的基本库(1)

栏目: Go · 发布时间: 6年前

内容简介:type Cmd struct     {Path        string//运行命令的路径,绝对路径或者相对路径

相关网站

https://golang.org/pkg

1.os.exec库

①exec中的一个结构体Cmd

type Cmd struct     {

Path        string//运行命令的路径,绝对路径或者相对路径

Args        []string // 命令参数

Env          []string       //进程环境,如果环境为空,则使用当前进程的环境

Dir          string//指定command的工作目录,如果dir为空,则comman在调用进程所在当前目录中运行

Stdin        io.Reader    //标准输入,先只要记住吧,有什么用再说。

Stdout      io.Writer      //标准输出,先只要记住吧,有什么用再说。

Stderr      io.Writer//错误输出,先只要记住吧,有什么用再说。

ExtraFiles  []*os.File

SysProcAttr  *syscall.SysProcAttr

Process      *os.Process    //Process是底层进程,只启动一次

ProcessState *os.ProcessState

//ProcessState包含一个退出进程的信息,当进程调用Wait或者Run时便会产生该信息.

}

②exec.Command()

模型:func Command(name string, arg ...string) *Cmd

//command返回cmd结构来执行带有相关参数的命令,它仅仅设定cmd结构中的Path和Args参数

注意,他仅仅设定了Cmd结构中的Path与Args

③exec.Lookpath()

模型:func LookPath(file string ) ( string , error )

LookPath searches for an executable named file in the directories named by the PATH environment variable. If file contains a slash (/) , it is tried directly and the PATH is not consulted. The result may be an absolute path or a path relative to the current directory.

④Cmd.Run 和 Cmd.Start 和 Cmd.Wait

func (c *Cmd) Run() error//开始指定命令并且等待他执行结束,如果命令能够成功执行完毕,则返回nil,否则的话边会产生错误

func (c *Cmd) Start() error//使某个命令开始执行,但是并不等到他执行结束,这点和Run命令有区别.然后使用Wait方法等待命令执

func (c *Cmd) Wait() error//Wait等待command退出,他必须和Start一起使用,如果命令能够顺利执行完并顺利退出则返回nil,否则的话便会返回error,其中Wait会是放掉所有与cmd命令相关的资源


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Introduction to Linear Optimization

Introduction to Linear Optimization

Dimitris Bertsimas、John N. Tsitsiklis / Athena Scientific / 1997-02-01 / USD 89.00

"The true merit of this book, however, lies in its pedagogical qualities which are so impressive..." "Throughout the book, the authors make serious efforts to give geometric and intuitive explanations......一起来看看 《Introduction to Linear Optimization》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具