Documentation ¶
Index ¶
- func Parse(cmd string) ([]string, error)
- func Run(cmdStr string) (result string)
- func RunWithContext(ctx context.Context, cmdStr string) string
- func RunWithContextVars(ctx context.Context, cmdStr string, variables *vars.Variables) string
- func RunWithVars(cmdStr string, variables *vars.Variables) string
- type CommandBuilder
- func Commands(cmds ...string) *CommandBuilder
- func CommandsWithContext(ctx context.Context, cmds ...string) *CommandBuilder
- func CommandsWithContextVars(ctx context.Context, variables *vars.Variables, cmds ...string) *CommandBuilder
- func CommandsWithVars(variables *vars.Variables, cmds ...string) *CommandBuilder
- func (cb *CommandBuilder) Add(cmds ...string) *CommandBuilder
- func (cb *CommandBuilder) Concurr() *CommandResult
- func (cb *CommandBuilder) Pipe() *PipedCommandResult
- func (cb *CommandBuilder) Run() *CommandResult
- func (cb *CommandBuilder) Start() *CommandResult
- func (cb *CommandBuilder) WithPolicy(policyMask CommandPolicy) *CommandBuilder
- func (cb *CommandBuilder) WithStderr(err io.Writer) *CommandBuilder
- func (cb *CommandBuilder) WithStdout(out io.Writer) *CommandBuilder
- func (cb *CommandBuilder) WithWorkDir(dir string) *CommandBuilder
- type CommandPolicy
- type CommandResult
- type PipedCommandResult
- type Proc
- func NewProc(cmdStr string) *Proc
- func NewProcWithContext(ctx context.Context, cmdStr string) *Proc
- func NewProcWithContextVars(ctx context.Context, cmdStr string, variables *vars.Variables) *Proc
- func NewProcWithVars(cmdStr string, variables *vars.Variables) *Proc
- func RunProc(cmdStr string) *Proc
- func RunProcWithContext(ctx context.Context, cmdStr string) *Proc
- func RunProcWithContextVars(ctx context.Context, cmdStr string, variables *vars.Variables) *Proc
- func RunProcWithVars(cmdStr string, variables *vars.Variables) *Proc
- func StartProc(cmdStr string) *Proc
- func StartProcWithContext(ctx context.Context, cmdStr string) *Proc
- func StartProcWithContextVars(ctx context.Context, cmdStr string, variables *vars.Variables) *Proc
- func StartProcWithVars(cmdStr string, variables *vars.Variables) *Proc
- func (p *Proc) Command() *osexec.Cmd
- func (p *Proc) Err() error
- func (p *Proc) ExitCode() int
- func (p *Proc) Exited() bool
- func (p *Proc) GetErrorPipe() io.Reader
- func (p *Proc) GetInputPipe() io.Writer
- func (p *Proc) GetOutputPipe() io.Reader
- func (p *Proc) ID() int
- func (p *Proc) IsSuccess() bool
- func (p *Proc) Kill() *Proc
- func (p *Proc) Out() io.Reader
- func (p *Proc) Peek() *Proc
- func (p *Proc) Result() string
- func (p *Proc) Run() *Proc
- func (p *Proc) SetGroupid(grp string) *Proc
- func (p *Proc) SetStderr(out io.Writer)
- func (p *Proc) SetStdin(in io.Reader)
- func (p *Proc) SetStdout(out io.Writer)
- func (p *Proc) SetUserid(user string) *Proc
- func (p *Proc) SetVars(variables *vars.Variables) *Proc
- func (p *Proc) SetWorkDir(path string) *Proc
- func (p *Proc) Start() *Proc
- func (p *Proc) Stderr() io.Writer
- func (p *Proc) Stdin() io.Reader
- func (p *Proc) Stdout() io.Writer
- func (p *Proc) SysTime() time.Duration
- func (p *Proc) UserTime() time.Duration
- func (p *Proc) Wait() *Proc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunWithContext ¶ added in v0.4.1
RunWithContext creates and runs a new process using the specified context. It waits for its result (combined stdin,stderr) and makes it availble as a string value. This is equivalent to calling Proc.RunProcWithContext() followed by Proc.Result().
func RunWithContextVars ¶ added in v0.4.1
RunWithContextVars creates and runs a new process with a specified context and session variables.
Types ¶
type CommandBuilder ¶ added in v0.1.1
type CommandBuilder struct {
// contains filtered or unexported fields
}
CommandBuilder is a batch command builder that can execute commands using different execution policies (i.e. serial, piped, concurrent)
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 CommandsWithContext ¶ added in v0.4.1
func CommandsWithContext(ctx context.Context, cmds ...string) *CommandBuilder
CommandsWithContext creates a *CommandBuilder, with specified context, used to collect command strings to be executed.
func CommandsWithContextVars ¶ added in v0.4.1
func CommandsWithContextVars(ctx context.Context, variables *vars.Variables, cmds ...string) *CommandBuilder
CommandsWithContextVars creates a *CommandBuilder with the specified context and session variables. The resulting *CommandBuilder is used to execute command strings.
func CommandsWithVars ¶ added in v0.3.0
func CommandsWithVars(variables *vars.Variables, cmds ...string) *CommandBuilder
CommandsWithVars creates a new CommandBuilder and sets session varialbes for it
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) Concurr ¶ added in v0.2.0
func (cb *CommandBuilder) Concurr() *CommandResult
Concurr starts all processes concurrently and does not wait for the commands to complete. It is equivalent to Commands(...).WithPolicy(ConcurrentExecPolicy).Start().
func (*CommandBuilder) Pipe ¶ added in v0.2.0
func (cb *CommandBuilder) Pipe() *PipedCommandResult
Pipe executes each command serially chaining the combinedOutput of previous command to the inputPipe of next command.
func (*CommandBuilder) Run ¶ added in v0.1.1
func (cb *CommandBuilder) Run() *CommandResult
Run executes all commands successively and waits for all of the result. The result of each individual command can be accessed from CommandResult.Procs[] after the execution completes. If policy == ExitOnErrPolicy, the execution will stop on the first error encountered, otherwise it will continue. Processes with errors can be accessed from CommandResult.ErrProcs.
func (*CommandBuilder) Start ¶ added in v0.1.1
func (cb *CommandBuilder) Start() *CommandResult
Start starts all processes sequentially by default, or concurrently if ConcurrentExecPolicy is set, and does not wait for the commands to complete. Use CommandResult.Wait to wait for the processes to complete. Then, the result of each command can be accessed from CommandResult.Procs[] or CommandResult.ErrProcs to access failed processses. If policy == ExitOnErrPolicy, the execution will halt on the first error encountered, otherwise it will continue.
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)
func (*CommandBuilder) WithStderr ¶ added in v0.4.0
func (cb *CommandBuilder) WithStderr(err io.Writer) *CommandBuilder
WithStderr sets the standard output err stream for the builder
func (*CommandBuilder) WithStdout ¶ added in v0.4.0
func (cb *CommandBuilder) WithStdout(out io.Writer) *CommandBuilder
WithStdout sets the standard output stream for the builder
func (*CommandBuilder) WithWorkDir ¶ added in v0.4.1
func (cb *CommandBuilder) WithWorkDir(dir string) *CommandBuilder
WithWorkDir sets the working directory for all defined commands
type CommandPolicy ¶ added in v0.1.1
type CommandPolicy byte
const ( ExitOnErrPolicy CommandPolicy = 1 << iota ConcurrentExecPolicy )
type CommandResult ¶ added in v0.2.0
type CommandResult struct {
// contains filtered or unexported fields
}
CommandResult stores results of executed commands using the CommandBuilder
func (*CommandResult) ErrProcs ¶ added in v0.2.0
func (cr *CommandResult) ErrProcs() []*Proc
ErrProcs returns errored processes
func (*CommandResult) ErrStrings ¶ added in v0.3.0
func (cr *CommandResult) ErrStrings() (errStrings []string)
ErrStrings returns errors as []string
func (*CommandResult) Errs ¶ added in v0.3.0
func (cr *CommandResult) Errs() (errs []error)
Errs returns all errors
func (*CommandResult) Procs ¶ added in v0.2.0
func (cr *CommandResult) Procs() []*Proc
Procs return all executed processes
func (*CommandResult) Wait ¶ added in v0.2.0
func (cr *CommandResult) Wait() *CommandResult
type PipedCommandResult ¶ added in v0.2.0
type PipedCommandResult struct {
// contains filtered or unexported fields
}
PipedCommandResult stores results of piped commands
func (*PipedCommandResult) ErrProcs ¶ added in v0.2.0
func (cr *PipedCommandResult) ErrProcs() []*Proc
ErrProcs returns errored piped processes
func (*PipedCommandResult) ErrStrings ¶ added in v0.3.0
func (cr *PipedCommandResult) ErrStrings() (errStrings []string)
ErrStrings returns errors as []string
func (*PipedCommandResult) Errs ¶ added in v0.3.0
func (cr *PipedCommandResult) Errs() (errs []error)
Errs returns all errors
func (*PipedCommandResult) LastProc ¶ added in v0.2.0
func (cr *PipedCommandResult) LastProc() *Proc
LastProc executes last executed process
func (*PipedCommandResult) Procs ¶ added in v0.2.0
func (cr *PipedCommandResult) Procs() []*Proc
Procs return all executed processes in pipe
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
NewProc sets up command string to be started as an OS process, however does not start the process. The process must be started using a subsequent call to Proc.StartXXX() or Proc.RunXXX() method.
func NewProcWithContext ¶ added in v0.4.1
NewProcWithContext sets up command string to be started as an OS process using the specified context. However, it does not start the process. The process must be started using a subsequent call to Proc.StartXXX() or Proc.RunXXX() method.
func NewProcWithContextVars ¶ added in v0.4.1
NewProcWithContextVars is a convenient function to create new Proc with context and variables.
func NewProcWithVars ¶ added in v0.3.0
NewProcWithVars sets up new command string and session variables for a new proc
func RunProc ¶
RunProc creates, starts, and runs for a new process using RunProcWithContext with a default context.
func RunProcWithContext ¶ added in v0.4.1
RunProcWithContext creates, starts, and runs an OS process using the specified context. It then waits for a new process (with combined stdout/stderr) to complete. Use Proc.Out() to access the command's output as an io.Reader, or use Proc.Result() to access the commands output as a string.
func RunProcWithContextVars ¶ added in v0.4.1
RunProcWithContextVars runs a process with a context and session variables
func RunProcWithVars ¶ added in v0.3.0
RunProcWithVars sets session variables and calls RunProc
func StartProc ¶
StartProc creates and starts an OS process using StartProcWithContext using a default context.
func StartProcWithContext ¶ added in v0.4.1
StartProcWithContext creates and starts an OS process (with combined stdout/stderr) using the specified context. The function does not wait for the process to complete and must be followed by proc.Wait() to wait for process completion. Then, call proc.Out() or proc.Result() to access the process' result.
func StartProcWithContextVars ¶ added in v0.4.1
StartProcWithContextVars is a convenient function that creates and starts a process with a context and variables.
func StartProcWithVars ¶ added in v0.3.0
StartProcWithVars sets session variables and calls StartProc to create and start a process.
func (*Proc) GetErrorPipe ¶ added in v0.2.0
GetErrorPipe returns a stream where the process error can be read from Deprecated: conflicts with the way the underlying exe.Command works
func (*Proc) GetInputPipe ¶ added in v0.2.0
GetInputPipe returns a stream where the process input can be written to Deprecated: conflicts with the way the underlying exe.Command works
func (*Proc) GetOutputPipe ¶ added in v0.2.0
GetOutputPipe returns a stream where the process output can be read from Deprecated: conflicts with the way the underlying exe.Command works
func (*Proc) Out ¶
Out returns the combined result (Stdout/Stderr) as a single reader if StartProc, RunProc, or Run package function was used to initiate the process. If Stdout/Stderr was set independently (i.e. with proc.Setstdout(...)) proc.Out will be nil.
NB: Out used to start/wait the process if necessary. However, that behavior has been deprecated. You must ensure the process has been properly initiated and wait for completion prior to calling Out.
func (*Proc) Result ¶
Result returns the combined stdout and stderr (see Proc.Out()) result as a string value. If there was a previous error in the call chain, this will return the error as a string.
func (*Proc) SetGroupid ¶ added in v0.4.1
SetGroupid looks up the group by a numerical id or by a name to be used for the process when launched.
func (*Proc) SetStderr ¶ added in v0.2.0
SetStderr sets a stream where the process can write its errors to
func (*Proc) SetStdin ¶ added in v0.2.0
SetStdin sets a stream for the process to read its input from
func (*Proc) SetStdout ¶ added in v0.2.0
SetStdout sets a stream where the process can write its output to
func (*Proc) SetUserid ¶ added in v0.4.1
SetUserid looks up the user by a numerical id or by a name to be used for the process when launched.
func (*Proc) SetWorkDir ¶ added in v0.4.1
SetWorkDir sets the working directory for the command
func (*Proc) Start ¶ added in v0.1.1
Start starts the associated command as an OS process and does not wait for its result. This call should follow a process creation using NewProc. If you don't want to use the internal combined output streams, make sure to configure access to the process' input/output (stdin,stdout,stderr) prior to calling Proc.Start().