The package supplies the common command execution supporting Go1.7+
.
$ go get -u github.com/xgfone/go-exec
package main
import (
"context"
"fmt"
"github.com/xgfone/go-exec"
)
const scripttmpl = `
ls %s
rm -rf %s
`
func main() {
exec.Execute(context.Background(), "mkdir", "testdir")
exec.ExecuteShellCmd(context.Background(), "echo abc > %s/%s", "testdir", "testfile")
data, _ := exec.OutputShellCmd(context.Background(), "cat %s/%s", "testdir", "testfile")
fmt.Println(data)
_, _, err := exec.RunShellScript(context.Background(), scripttmpl, "testdir", "testdir")
fmt.Println(err)
// Output:
// abc
//
// <nil>
}