exec

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2021 License: MIT Imports: 10 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(cmdStr string) (result string)

Run creates and runs a process and returns the result as a string. Equivalent to: Proc.RunProc() -> Proc.Result()

Types

type CommandBuilder added in v0.1.1

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

func Commands added in v0.1.1

func Commands(cmds ...string) *CommandBuilder

Commands creates a *CommandBuilder used to collect command strings to be executed.

func (*CommandBuilder) Add added in v0.1.1

func (cb *CommandBuilder) Add(cmds ...string) *CommandBuilder

Add adds a new command string to the builder

func (*CommandBuilder) ConcurRun added in v0.1.1

func (cb *CommandBuilder) ConcurRun() CommandProcs

ConcurRun is a shortcut for executing procs concurrently:

cb.WithPolicy(CmdExecConcurrent).Start().Wait()

func (*CommandBuilder) Run added in v0.1.1

func (cb *CommandBuilder) Run() CommandProcs

Run is a shortcut for executing the procs serially:

cb.WithPolicy(CmdOnErrContinue).Start().Wait()

func (*CommandBuilder) Start added in v0.1.1

func (cb *CommandBuilder) Start() *CommandBuilder

Start starts running the registered procs serially and returns immediately. This should be followed by a call to Wait to retrieve results.

func (*CommandBuilder) Wait added in v0.1.1

func (cb *CommandBuilder) Wait() CommandProcs

func (*CommandBuilder) WithPolicy added in v0.1.1

func (cb *CommandBuilder) WithPolicy(policyMask CommandPolicy) *CommandBuilder

WithPolicy sets one or more command policy mask values, i.e. (CmdOnErrContinue | CmdExecConcurrent)

type CommandPolicy added in v0.1.1

type CommandPolicy byte
const (
	CmdOnErrContinue CommandPolicy = 1 << iota
	CmdOnErrExit
	CmdExecSerial
	CmdExecConcurrent
	CmdExecPipe
)

type CommandProcs added in v0.1.1

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

type Proc

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

Proc stores process info when running a process

func NewProc added in v0.1.1

func NewProc(cmdStr string) *Proc

NewProc sets up command string to be started as an OS process, however does not start the process.

func RunProc

func RunProc(cmdStr string) *Proc

RunProc creates, runs, and waits for a process to complete and return *Proc with result info. This call must be followed by Proc.Result() to access command result as a string value. NOTE: using proc.Out(), after this call, will be empty.

func StartProc

func StartProc(cmdStr string) *Proc

StartProc sets up and starts an OS process, but does not wait for it to complete (use proc.Wait for that)

func (*Proc) Command

func (p *Proc) Command() *osexec.Cmd

Commands returns the os/exec.Cmd that started the process

func (*Proc) Err

func (p *Proc) Err() error

Err returns any execution error

func (*Proc) ExitCode

func (p *Proc) ExitCode() int

ExitCode returns process exit code

func (*Proc) Exited

func (p *Proc) Exited() bool

Exited returns true if process exits ok

func (*Proc) ID

func (p *Proc) ID() int

ID returns process id

func (*Proc) IsSuccess

func (p *Proc) IsSuccess() bool

IsSuccess returns true if proc exit ok

func (*Proc) Kill

func (p *Proc) Kill() *Proc

Kill halts the process

func (*Proc) Out

func (p *Proc) Out() io.Reader

Out waits for cmd result and surfaces the result from both stdout and stderr in an io.Reader that can be streamed. NOTE: Must be called after Proc.StartProc

func (*Proc) Peek

func (p *Proc) Peek() *Proc

Peek attempts to read process state information

func (*Proc) Result

func (p *Proc) Result() string

Result waits and copies the result of the combined stdout and stderr and returns its result as a string. NOTE: Must be called after Proc.StartProc, Proc.RunProc() or Proc.Run().

func (*Proc) Start added in v0.1.1

func (p *Proc) Start() *Proc

Start starts the associated command as an OS process Errors can be accessed using p.Err()

func (*Proc) StdErr

func (p *Proc) StdErr() io.Reader

StdErr is an io.Reader pipe for standard error Must be streamed before Proc.Wait().

func (*Proc) StdOut

func (p *Proc) StdOut() io.Reader

StdOut is an io.Reader pipe for standard out Must be streamed before Proc.Wait()

func (*Proc) SysTime

func (p *Proc) SysTime() time.Duration

SysTime returns proc system cpu time

func (*Proc) UserTime

func (p *Proc) UserTime() time.Duration

UserTime returns proc user cpu time

func (*Proc) Wait

func (p *Proc) Wait() *Proc

Wait waits for a process started with Proc.StartProc to complete (in a separate goroutine). Once process completes, Wait cleans up resources. Must be called after Proc.StartProc()

Jump to

Keyboard shortcuts

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