cmd

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 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 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 WaitCmd added in v0.2.2

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

WaitCmd wait command exit Must called after StartCmd

Types

type Cfg

type Cfg struct {
	Command    []string          `json:"command"    validate:"required,min=1" 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 StartCmd added in v0.2.2

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

StartCmd start a command if error is nil, you can get pid from Result.Pid. Must call WaitCmd after StartCmd whether error is nil or not

Jump to

Keyboard shortcuts

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