go 执行shell 同步与异步方式
2017-12-19 14:50
2371 查看
if cmdSaved != "" { lsCmd := exec.Command("/bin/sh", "-c", cmdSaved) err = lsCmd.Start() if err != nil { log.Error("command not ok") outM := &outMessage{ NOK_FILE_EXCEPTION, taskid, "cmd saved not executed ok", } b, err := json.Marshal(outM) if err != nil { log.Fatal("json encode message failed") w.Write([]byte("{\"result\":10,\"message\":\"encode resp message error\"}")) } else { w.Write([]byte(string(b))) } return } }
func Command
原型:
func Command(name string, arg ...string) *Cmd1
[/code]
作用:Command returns the Cmd struct to execute the named program with the given arguments.
例如:
cmd := exec.Command(“/bin/bash”, “-c”, “ls”)
cmd := exec.Command(“tr”, “a-z”, “A-Z”)
func (*Cmd) Run
func (c *Cmd) Output() ([]byte, error)1
[/code]
作用:开始运行并等待结束。
这里需要注意Run和Start的区别:
Start starts the specified command but does not wait for it to complete.
开始运行不等待结束。
相关文章推荐
- Go语言同步与异步执行多个任务封装详解(Runner和RunnerAsync)
- GCD编程dispatch_sync(同步)和dispatch_async(异步)方式执行并发队列任务区别
- GCD-同步,异步分别在串行队列,并发队列,主队列下的执行方式
- js文件引用方式及其同步执行与异步执行
- js文件引用方式及其同步执行与异步执行
- 浅谈js文件引用方式及其同步执行与异步执行
- 异步执行方式改称同步执行方式
- Go语言同步和异步执行多个任务封装
- shell 执行脚本的 3 种方式
- linux - shell脚本执行方式
- 使用GCD异步和同步执行任务
- jquery ajax 同步异步的执行
- shell学习之shell执行方式及排错
- Linux下Shell脚本的基本执行方式
- CVE-2017-17562 GoAhea远程代码执行反弹shell姿势
- jquery ajax 同步异步的执行
- 同步、异步转化和任务执行
- Python 中的串行执行 并发执行 同步异步