Documentation
¶
Index ¶
- Constants
- Variables
- type CmdWorker
- func (w *CmdWorker) Run(stdin io.Reader) (status gocmd.Status, err error)
- func (w *CmdWorker) SetOutputHandler(outputHandler func(OutputStatus) bool)
- func (w *CmdWorker) SetReadInterval(t time.Duration)
- func (w *CmdWorker) SetReadTimeout(t time.Duration)
- func (w *CmdWorker) SetTimeout(t time.Duration)
- func (w *CmdWorker) Stop()
- type InterruptedError
- type OutputStatus
Constants ¶
const ( InterruptedByTimer = 1 InterruptedByOutputHandler = 2 )
Variables ¶
var ( DefTimeout = time.Second * 120 //timeout the cmd must finished DefReadTimeout = time.Second * 30 //timeout waiting new data from stdout/stderr DefReadInterval = time.Second * 1 //the interval outputHandler is called to process the output )
var (
ErrOperation = errors.New("command finished with error")
)
Functions ¶
This section is empty.
Types ¶
type CmdWorker ¶
func NewCmdWorker ¶
func NewCmdWorker(cmd string, args []string, outputHandler func(OutputStatus) bool) CmdWorker
NewCmdWorker creates new worker with cmd as console command, args as command args and outputHandler callback function outputHandler calls every readInterval and used to process a command output, can be nil
func (*CmdWorker) Run ¶
Run starts the command and blocked until command finished or timeout happened stdin is a io.Reader where the cmd input is reading from, can be nil status is gocmd.Status struct describing running command err is nil on success, ErrOperation when command is finished with exit status != 0 or InterruptedError type when command was interrupted with timeout or by OutputHandler
func (*CmdWorker) SetOutputHandler ¶
func (w *CmdWorker) SetOutputHandler(outputHandler func(OutputStatus) bool)
SetOutputHandler sets command's output callback which is called on every ReadInterval tick outputHandler callback should return true to continue command execution, or false to abort command execution
func (*CmdWorker) SetReadInterval ¶
SetReadInterval sets command's ReadInterval, outputHandler callback is called on every ReadInterval tick
func (*CmdWorker) SetReadTimeout ¶
SetReadTimeout sets command read timeout
func (*CmdWorker) SetTimeout ¶
SetTimeout sets command's execution timeout
type InterruptedError ¶
type InterruptedError struct {
Reason int
}
func (*InterruptedError) Error ¶
func (e *InterruptedError) Error() (str string)