https://github.com/mibk/shellexec
a convenience package for shell-like execution of commands in Go
https://github.com/mibk/shellexec
go golang golang-library shell
Last synced: 12 months ago
JSON representation
a convenience package for shell-like execution of commands in Go
- Host: GitHub
- URL: https://github.com/mibk/shellexec
- Owner: mibk
- License: mit
- Created: 2017-09-23T00:27:40.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-09T07:46:03.000Z (over 8 years ago)
- Last Synced: 2024-06-19T05:44:10.977Z (about 2 years ago)
- Topics: go, golang, golang-library, shell
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 12
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# shellexec [](https://godoc.org/github.com/mibk/shellexec)
Package shellexec provides cross-platform shell-like command execution. It
supports a small subset of the Shell Command Language related to executing
of commands. Package shellexec isn't a replacement for `os/exec`. It's rather
just a convenience package for use-cases that require/prefer having just a
single string to define the command to execute.
## Installation
```bash
$ go get github.com/mibk/shellexec
```
## Example
```go
package main
import (
"log"
"os"
"github.com/mibk/shellexec"
)
func main() {
run(`echo 'Sup'ports "\"quotes\","`)
run(`VARIABLE=assignment, X=3 env`)
run(`echo "and variable expansion, $USER."`)
run(`echo Returns just '"os/exec".Cmd,' that can be`)
run(`echo further adjusted before running.`)
run(`echo The goal is to support a really \*small\* subset`)
run(`echo of the Shell language while being 100\% compatible.`)
}
func run(command string) {
cmd, err := shellexec.Command(command)
if err != nil {
log.Fatal(err)
}
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
}
```