https://github.com/nhatthm/go-exec
Runs external commands
https://github.com/nhatthm/go-exec
cli command command-line command-line-tool commands exec go golang
Last synced: 5 months ago
JSON representation
Runs external commands
- Host: GitHub
- URL: https://github.com/nhatthm/go-exec
- Owner: nhatthm
- License: mit
- Created: 2023-03-21T21:49:35.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-03-22T08:23:00.000Z (over 1 year ago)
- Last Synced: 2025-08-19T00:32:15.493Z (11 months ago)
- Topics: cli, command, command-line, command-line-tool, commands, exec, go, golang
- Language: Go
- Homepage:
- Size: 61.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Exec
[](https://github.com/nhatthm/go-exec/releases/latest)
[](https://github.com/nhatthm/go-exec/actions/workflows/test.yaml)
[](https://codecov.io/gh/nhatthm/go-exec)
[](https://goreportcard.com/report/go.nhat.io/exec)
[](https://pkg.go.dev/go.nhat.io/exec)
[](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)
Package `exec` runs external commands.
## Prerequisites
- `Go >= 1.22`
## Install
```bash
go get go.nhat.io/exec
```
## Usage
Run a command:
```go
package example_test
import (
"bytes"
"fmt"
"go.nhat.io/exec"
)
func ExampleRun() {
outBuf := new(bytes.Buffer)
errBuf := new(bytes.Buffer)
_, err := exec.Run("echo", exec.WithArgs("hello world"),
exec.WithStdout(outBuf),
exec.WithStderr(errBuf),
)
if err != nil {
panic(err)
}
fmt.Println(outBuf.String())
fmt.Println(errBuf.String())
// Output:
// hello world
//
}
```
Run a command with pipes:
```go
package example_test
import (
"bytes"
"fmt"
"go.nhat.io/exec"
)
func ExampleRun_pipe() {
outBuf := new(bytes.Buffer)
errBuf := new(bytes.Buffer)
_, err := exec.Run("echo", exec.WithArgs("hello world"),
exec.WithStdout(outBuf),
exec.WithStderr(errBuf),
exec.Pipe("grep", "-o", "hello"),
exec.Pipe("tr", "[:lower:]", "[:upper:]"),
)
if err != nil {
panic(err)
}
fmt.Println(outBuf.String())
fmt.Println(errBuf.String())
// Output:
// HELLO
//
}
```
## Donation
If this project help you reduce time to develop, you can give me a cup of coffee :)
### Paypal donation
[](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)
or scan this