cmd

package
v0.12.19 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: MIT Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSignaled

func IsSignaled(err error) bool

IsSignaled check if cmd exit signaled, err is Cmd.Wait() or Cmd.Run() error.

func KillGroup added in v0.11.11

func KillGroup(cmd *exec.Cmd) error

func MustStop

func MustStop(ctx context.Context, cmd *exec.Cmd, singleSigWaitExitSec int, sig ...syscall.Signal) error

func MustStopGroup added in v0.11.11

func MustStopGroup(ctx context.Context, cmd *exec.Cmd, singleSigWaitExitSec int, sig ...syscall.Signal) error

func Stop

func Stop(cmd *exec.Cmd) error

func StopGroup added in v0.11.11

func StopGroup(cmd *exec.Cmd) error

Types

type Cfg

type Cfg struct {
	Command                   []string          `json:"command"                   yaml:"command"  validate:"required"`
	Env                       map[string]string `json:"env"                       yaml:"env"`
	RunAsUser                 string            `json:"runAsUser"                 yaml:"runAsUser"`
	WorkingDir                string            `json:"workingDir"                yaml:"workingDir"`
	SetPgid                   bool              `json:"setPgid"                   yaml:"setPgid"`
	WaitSecBetweenKillSignals int               `json:"waitSecBetweenKillSignals" yaml:"waitSecBetweenKillSignals"`
}

func NewCfg added in v0.11.0

func NewCfg() *Cfg

type Result

type Result struct {
	Stdout        []string `json:"stdout"`
	Stderr        []string `json:"stderr"`
	ExitCode      int      `json:"exitCode"`
	Pid           int      `json:"pid"`
	StartTimeNano int64    `json:"startTimeNano"`
	StopTimeNano  int64    `json:"stopTimeNano"`
	Signaled      bool     `json:"signaled"`
	// contains filtered or unexported fields
}

func Exec added in v0.12.13

func Exec(ctx context.Context, command ...string) *Result

func Run

func Run(ctx context.Context, cfg *Cfg, beforeStart ...func(cmd *exec.Cmd)) *Result

func Start added in v0.8.2

func Start(ctx context.Context, cfg *Cfg, beforeStart ...func(cmd *exec.Cmd)) *Result

Start command you can get pid from Result.Pid before <-Result.Done(), 0 means start fail.

func (*Result) Cmd added in v0.12.13

func (r *Result) Cmd() *exec.Cmd

func (*Result) Done added in v0.11.0

func (r *Result) Done() <-chan struct{}

func (*Result) Err added in v0.11.0

func (r *Result) Err() error

func (*Result) String added in v0.11.2

func (r *Result) String() string

Jump to

Keyboard shortcuts

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