https://github.com/xgfone/go-exec
The common command execution.
https://github.com/xgfone/go-exec
command commander exec execute execution executor
Last synced: 11 months ago
JSON representation
The common command execution.
- Host: GitHub
- URL: https://github.com/xgfone/go-exec
- Owner: xgfone
- License: apache-2.0
- Created: 2021-05-23T14:08:19.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-11-02T06:20:38.000Z (over 2 years ago)
- Last Synced: 2025-01-31T08:43:50.011Z (about 1 year ago)
- Topics: command, commander, exec, execute, execution, executor
- Language: Go
- Homepage:
- Size: 36.1 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Command Execution [](https://github.com/xgfone/go-exec/actions/workflows/go.yml) [](https://pkg.go.dev/github.com/xgfone/go-exec) [](https://raw.githubusercontent.com/xgfone/go-exec/master/LICENSE)
The package supplies the common command execution supporting `Go1.7+`.
## Install
```shell
$ go get -u github.com/xgfone/go-exec
```
## Example
```go
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
//
//
}
```