Documentation ¶
Overview ¶
Package exec implements a minimalized external process launcher. It exists to work around some shortcomings for Windows scenarios that aren't exposed via the os/exec package.
Index ¶
- type Exec
- type ExecOpts
- func WithConPty(cpty *conpty.Pty) ExecOpts
- func WithDir(dir string) ExecOpts
- func WithEnv(env []string) ExecOpts
- func WithJobObject(job *jobobject.JobObject) ExecOpts
- func WithProcessFlags(flags uint32) ExecOpts
- func WithStdio(stdout, stderr, stdin bool) ExecOpts
- func WithToken(token windows.Token) ExecOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exec ¶
type Exec struct {
// contains filtered or unexported fields
}
Exec is an object that represents an external process. A user should NOT initialize one manually and instead should call New() and pass in the relevant options to retrieve one.
The Exec object is not intended to be used across threads and most methods should only be called once per object. It's expected to follow one of two conventions for starting and managing the lifetime of the process.
Either: New() -> e.Start() -> e.Wait() -> (Optional) e.ExitCode()
or: New() -> e.Run() -> (Optional) e.ExitCode()
To capture output or send data to the process, the Stdin(), StdOut() and StdIn() methods can be used.
func New ¶
New returns a new instance of an `Exec` object. A process is not running at this point and must be started via either Run(), or a combination of Start() + Wait().
func (*Exec) ExitCode ¶
ExitCode returns the exit code of the process. If the process hasn't exited, this will return -1.
func (*Exec) Pid ¶
Pid returns the pid of the running process. If the process isn't running, this will return -1.
func (*Exec) Run ¶
Run will run the process to completion. This can be accomplished manually by calling Start + Wait afterwards.
func (*Exec) Start ¶
Start starts the process with the path and cmdline specified when the Exec object was created. This does not wait for exit or release any resources, a call to Wait must be made afterwards.
func (*Exec) Stderr ¶
Stderr returns the pipe standard error is hooked up to. It's expected that the client will continuously drain the pipe if standard output is requested. This will be closed once Wait returns.
func (*Exec) Stdin ¶
Stdin returns the pipe standard input is hooked up to. This will be closed once Wait returns.
type ExecOpts ¶
type ExecOpts func(e *execConfig) error
func WithConPty ¶
WithConPty will launch the created process with a pseudo console attached to the process.
func WithJobObject ¶
WithJobObject will launch the newly created process in the passed in job.
func WithProcessFlags ¶
WithProcessFlags will pass `flags` to CreateProcess's creationFlags parameter.