Golang toolkit for robust, object-oriented execution and management of OS shell commands with context support, output handling, and error management.
- Simple API for executing shell commands in OOP style
- Pass command arguments and environment variables
- Synchronous and asynchronous execution with context.Context support
- Capture and process stdout/stderr output
- Retrieve and handle process exit codes
- Robust error handling for command execution
- Minimal dependencies, cross-platform (works on all Go-supported OSes)
- Clean, extensible interfaces for integration into other projects
go get github.com/sitnikovik/osxecimport (
"context"
"log"
"github.com/sitnikovik/osxec/command"
"github.com/sitnikovik/osxec/process"
"github.com/sitnikovik/osxec/shell"
)
func main() {
ctx := context.Background()
res := process.
NewProcess(
shell.NewShell(),
command.NewCommand("echo", "Hello, World!"),
).
Execution(ctx)
if err := res.Err(); err != nil {
log.Fatalf("Process execution failed: %v", err)
return
}
log.Printf("Process output as string: '%s'\n", res.String())
}Full API reference is available on pkg.go.dev
- Go 1.23.4 (as declared in
go.mod) — newer Go versions should work - No external runtime dependencies
Contributions are welcome. Suggested workflow:
- Pick an open issue and work on it. Open a Pull Request that references the issue when you're ready
- If there is no suitable issue for your idea, either open a short issue describing the proposal or contact me (watch my bio) and we will create an issue for you.
- Fork the repository and create a feature branch:
git checkout -b feature/name - Run and add tests for new behavior:
go test ./... - Commit changes with a descriptive message and open a Pull Request
- Follow the repository's code style and linters (we use
golangci-lint) - If the PR passes, we merge it and create version via GitHub releases
Please open an issue to discuss large or breaking changes before implementing.
This project is licensed under the MIT License — see the LICENSE file for details.
Maintained by Ilya Sitnikov