cmd

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 11 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() result error.

func MustStop

func MustStop(ctx context.Context, cmd *exec.Cmd) error

func Stop

func Stop(cmd *exec.Cmd) error

func Wait added in v0.8.2

func Wait(ctx context.Context, cmd *exec.Cmd, startResult *Result) error

Wait wait command exit Must called after Start.

Types

type Cfg

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

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 Run

func Run(command ...string) (*Result, error)

func RunCmd

func RunCmd(ctx context.Context, cmd *exec.Cmd, cfg *Cfg, beforeRun ...func(cmd *exec.Cmd) error) (*Result, error)

func RunRaw

func RunRaw(ctx context.Context, cfg *Cfg, beforeRun ...func(cmd *exec.Cmd) error) (*Result, error)

func Start added in v0.8.2

func Start(cmd *exec.Cmd, beforeRun ...func(cmd *exec.Cmd) error) *Result

Start start a command you can get pid from Result.Pid, 0 means start fail. Must call Wait after Start whether cmd fail or not.

Jump to

Keyboard shortcuts

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