/gorun

gorun is a Go package that provides a simple interface to run, monitor, and stop external programs, capturing their output and handling graceful shutdowns.

Primary LanguageGoMIT LicenseMIT

gorun

Project Badges

gorun is a Go package that provides a simple interface to run, monitor, and stop external programs, capturing their output and handling graceful shutdowns.

Usage

Installation

gorun

Small helper to run/monitor/stop external programs from Go.

Usage (essential)

Install:

go get github.com/cdvelop/gorun

Minimal example (use WorkingDir when child needs a specific CWD):

cfg := &gorun.Config{
    ExecProgramPath: "./my-server",
    WorkingDir:      "/abs/path/to/project/pwa", // optional
    ExitChan:        make(chan bool),
}
r := gorun.New(cfg)
_ = r.RunProgram()
// ... stop when needed
_ = r.StopProgram()
// By default gorun captures output internally. For programmatic access in
// tests prefer not to rely on exported getters; pass a `Logger` (io.Writer)
// to receive forwarded output, or inspect the internal buffer from tests.

Notes

  • WorkingDir: optional; if empty child inherits parent's CWD. Prefer absolute paths.
  • Logger: optional io.Writer. gorun captures output internally; use GetOutput() in tests or when you need programmatic access.

Tests

cd gorun
go test ./... -v
go test ./... -race -v  # run with race detector

That's it — small, focused, non-redundant docs. If you want, I can add one short goserver example showing how to set WorkingDir from an AutoConfig.

These tests exercise WorkingDir handling and cleanup behaviors.