Documentation ¶
Index ¶
- Variables
- func AttachStderrListener(cmd *exec.Cmd, listener OutputListener) error
- func AttachStdoutListener(cmd *exec.Cmd, listener OutputListener) error
- func PipeCommands(commands ...*exec.Cmd) ([]byte, error)
- func TellCommandNotToSpawnShell(cmd *exec.Cmd)
- type OutputListener
- type Process
- func (p *Process) GetArgs() []string
- func (p *Process) GetDir() string
- func (p *Process) Kill() error
- func (p *Process) RedirectStderrTo(out io.Writer)
- func (p *Process) RedirectStdoutTo(out io.Writer)
- func (p *Process) Run() error
- func (p *Process) RunAndCaptureOutput(ctx context.Context) ([]byte, []byte, error)
- func (p *Process) RunWithinContext(ctx context.Context) error
- func (p *Process) SetDir(dir string)
- func (p *Process) SetDirFromPath(path *paths.Path)
- func (p *Process) SetEnvironment(values []string)
- func (p *Process) Signal(sig os.Signal) error
- func (p *Process) Start() error
- func (p *Process) StderrPipe() (io.ReadCloser, error)
- func (p *Process) StdinPipe() (io.WriteCloser, error)
- func (p *Process) StdoutPipe() (io.ReadCloser, error)
- func (p *Process) Wait() error
Constants ¶
This section is empty.
Variables ¶
var NullReader = &nullReader{}
NullReader is an io.Reader that will always return EOF
var NullWriter = &nullWriter{}
NullWriter is an io.Writer that discards any output
var PrintToStderr = &printToStderr{}
PrintToStderr is an OutputListener that outputs messages to standard error
var PrintToStdout = &printToStdout{}
PrintToStdout is an OutputListener that outputs messages to standard output
Functions ¶
func AttachStderrListener ¶
func AttachStderrListener(cmd *exec.Cmd, listener OutputListener) error
AttachStderrListener adds an OutputListener to the stderr of the process
func AttachStdoutListener ¶
func AttachStdoutListener(cmd *exec.Cmd, listener OutputListener) error
AttachStdoutListener adds an OutputListener to the stdout of the process
func PipeCommands ¶
PipeCommands executes the commands received as input by feeding the output of one to the input of the other, exactly like Unix Pipe (|). Returns the output of the final command and the eventual error.
code inspired by https://gist.github.com/tyndyll/89fbb2c2273f83a074dc
func TellCommandNotToSpawnShell ¶
TellCommandNotToSpawnShell avoids that the specified Cmd display a small command prompt while runnning on Windows. It has no effects on other OS.
Types ¶
type OutputListener ¶
type OutputListener interface {
Output(msg string)
}
OutputListener is a callback interface to receive output messages from process
type Process ¶
type Process struct {
// contains filtered or unexported fields
}
Process is representation of an external process run
func NewProcess ¶
NewProcess creates a command with the provided command line arguments and environment variables (that will be added to the parent os.Environ). The argument args[0] is the path to the executable, the remainder are the arguments to the command.
func NewProcessFromPath ¶
func NewProcessFromPath(extraEnv []string, executable *paths.Path, args ...string) (*Process, error)
NewProcessFromPath creates a command from the provided executable path, additional environment vars (in addition to the system default ones) and command line arguments.
func (*Process) Kill ¶
Kill causes the Process to exit immediately. Kill does not wait until the Process has actually exited. This only kills the Process itself, not any other processes it may have started.
func (*Process) RedirectStderrTo ¶
RedirectStderrTo will redirect the process' stdout to the specified writer. Any previous redirection will be overwritten.
func (*Process) RedirectStdoutTo ¶
RedirectStdoutTo will redirect the process' stdout to the specified writer. Any previous redirection will be overwritten.
func (*Process) RunAndCaptureOutput ¶
RunAndCaptureOutput starts the specified command and waits for it to complete. If the given context is canceled before the normal process termination, the process is killed. The standard output and standard error of the process are captured and returned at process termination.
func (*Process) RunWithinContext ¶
RunWithinContext starts the specified command and waits for it to complete. If the given context is canceled before the normal process termination, the process is killed.
func (*Process) SetDir ¶
SetDir sets the working directory of the command. If Dir is the empty string, Run runs the command in the calling process's current directory.
func (*Process) SetDirFromPath ¶
func (p *Process) SetDirFromPath(path *paths.Path)
SetDirFromPath sets the working directory of the command. If path is nil, Run runs the command in the calling process's current directory.
func (*Process) SetEnvironment ¶
SetEnvironment set the environment for the running process. Each entry is of the form "key=value". System default environments will be wiped out.
func (*Process) Signal ¶
Signal sends a signal to the Process. Sending Interrupt on Windows is not implemented.
func (*Process) StderrPipe ¶
func (p *Process) StderrPipe() (io.ReadCloser, error)
StderrPipe returns a pipe that will be connected to the command's standard error when the command starts.
Wait will close the pipe after seeing the command exit, so most callers don't need to close the pipe themselves. It is thus incorrect to call Wait before all reads from the pipe have completed. For the same reason, it is incorrect to use Run when using StderrPipe.
func (*Process) StdinPipe ¶
func (p *Process) StdinPipe() (io.WriteCloser, error)
StdinPipe returns a pipe that will be connected to the command's standard input when the command starts. The pipe will be closed automatically after Wait sees the command exit. A caller need only call Close to force the pipe to close sooner. For example, if the command being run will not exit until standard input is closed, the caller must close the pipe.
func (*Process) StdoutPipe ¶
func (p *Process) StdoutPipe() (io.ReadCloser, error)
StdoutPipe returns a pipe that will be connected to the command's standard output when the command starts.
Wait will close the pipe after seeing the command exit, so most callers don't need to close the pipe themselves. It is thus incorrect to call Wait before all reads from the pipe have completed. For the same reason, it is incorrect to call Run when using StdoutPipe.