process

package
v1.16.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OutputWriter

type OutputWriter struct {
	// contains filtered or unexported fields
}

func (*OutputWriter) Write

func (w *OutputWriter) Write(p []byte) (n int, err error)

type Process

type Process struct {
	// contains filtered or unexported fields
}

func New

func New() *Process

func (*Process) Env

func (r *Process) Env(vars map[string]string) contractsprocess.Process

func (*Process) Input

func (r *Process) Input(in io.Reader) contractsprocess.Process

func (*Process) OnOutput

func (*Process) Path

func (r *Process) Path(path string) contractsprocess.Process

func (*Process) Quietly

func (r *Process) Quietly() contractsprocess.Process

func (*Process) Run

func (r *Process) Run(name string, args ...string) (contractsprocess.Result, error)

func (*Process) Start

func (r *Process) Start(name string, args ...string) (contractsprocess.Running, error)

func (*Process) TTY

func (r *Process) TTY() contractsprocess.Process

func (*Process) Timeout

func (r *Process) Timeout(timeout time.Duration) contractsprocess.Process

func (*Process) WithContext

func (r *Process) WithContext(ctx context.Context) contractsprocess.Process

type Result

type Result struct {
	// contains filtered or unexported fields
}

func NewResult

func NewResult(exitCode int, command, stdout, stderr string) *Result

func (*Result) Command

func (r *Result) Command() string

func (*Result) ErrorOutput

func (r *Result) ErrorOutput() string

func (*Result) ExitCode

func (r *Result) ExitCode() int

func (*Result) Failed

func (r *Result) Failed() bool

func (*Result) Output

func (r *Result) Output() string

func (*Result) SeeInErrorOutput

func (r *Result) SeeInErrorOutput(needle string) bool

func (*Result) SeeInOutput

func (r *Result) SeeInOutput(needle string) bool

func (*Result) Successful

func (r *Result) Successful() bool

type Running

type Running struct {
	// contains filtered or unexported fields
}

func NewRunning

func NewRunning(cmd *exec.Cmd, stdout, stderr *bytes.Buffer) *Running

func (*Running) Command

func (r *Running) Command() string

func (*Running) ErrorOutput

func (r *Running) ErrorOutput() string

func (*Running) Kill

func (r *Running) Kill() error

func (*Running) LatestErrorOutput

func (r *Running) LatestErrorOutput() string

func (*Running) LatestOutput

func (r *Running) LatestOutput() string

func (*Running) Output

func (r *Running) Output() string

func (*Running) PID

func (r *Running) PID() int

func (*Running) Running

func (r *Running) Running() bool

Running actively queries the OS to see if the process still exists.

NOTE: This method returns `true` for a "zombie" process (one that has terminated but has not been reaped by a call to `Wait()`). Due to this, a monitoring loop requires a concurrent call to `result.Wait()` to ensure termination.

Correct Usage Example:

done := make(chan struct{})
result, _ := process.New().Start("sleep", "2")

go func() {
    defer close(done)
    // This loop will continue as long as the process is running OR a zombie.
    for result.Running() {
        fmt.Println("Process is still running...")
        time.Sleep(500 * time.Millisecond)
    }
}()

// This call is mandatory. It blocks, reaps the zombie, and allows the goroutine to exit.
result.Wait()
<-done // Wait for monitoring goroutine to finish.

func (*Running) Signal

func (r *Running) Signal(sig os.Signal) error

func (*Running) Stop

func (r *Running) Stop(timeout time.Duration, sig ...os.Signal) error

Stop gracefully stops the process by sending SIGTERM and waiting for a timeout.

func (*Running) Wait

func (r *Running) Wait() contractsprocess.Result

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL