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.
Usage
Installation
go get github.com/cdvelop/gorun
Example
package main
import (
"os"
"github.com/cdvelop/gorun"
)
func main() {
config := &gorun.GoRunConfig{
ExecProgramPath: "your_program",
RunArguments: func() []string { return []string{"--flag"} },
ExitChan: make(chan bool),
Writer: os.Stdout,
}
runner := gorun.New(config)
// Start the program
if err := runner.RunProgram(); err != nil {
panic(err)
}
// ... do other work ...
// Stop the program gracefully
if err := runner.StopProgram(); err != nil {
panic(err)
}
}
API
type GoRunConfig
Configuration for running an external program.
ExecProgramPath string: Path to the executable.
RunArguments func() []string: Function returning the arguments to pass.
ExitChan chan bool: Channel to signal exit.
Writer io.Writer: Where to write program output.
func New(config *GoRunConfig) *GoRun
Creates a new runner instance.
func (g *GoRun) RunProgram() error
Runs the configured program and captures its output.
func (g *GoRun) StopProgram() error
Stops the running program gracefully.
For more details, see the GoDoc or the source