Golang os/exec.Cmd.Run() function examples

package os

Golang os/exec.Cmd.Run() function usage examples

NOTE : Run() starts the specified command and waits for it to complete. (asynchronous) as oppose to Start() which is (synchronous)

Example 1:

 cmd := exec.Command("git", "clone", scheme+"://"+repo+".git", dir)
 log.Println(strings.Join(cmd.Args, " "))
 if err := cmd.Run(); err != nil {
 return err
 }

Example 2:

 err := exec.Command("go", "get", "github.com/go-bootstrap/go-bootstrap").Run()

Reference :

http://golang.org/pkg/os/exec/#Cmd.Run

Advertisement