package exec
import "github.com/Microsoft/hcsshim/internal/exec"
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
- func New(path, cmdLine string, opts ...ExecOpts) (*Exec, error)
- func (e *Exec) ExitCode() int
- func (e *Exec) Exited() bool
- func (e *Exec) Kill() error
- func (e *Exec) Pid() int
- func (e *Exec) Run() error
- func (e *Exec) Start() error
- func (e *Exec) Stderr() *os.File
- func (e *Exec) Stdin() *os.File
- func (e *Exec) Stdout() *os.File
- func (e *Exec) Wait() (err error)
- 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
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) Exited ¶
Exited returns if the process has exited.
func (*Exec) Kill ¶
Kill will forcefully kill the process.
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.
func (*Exec) Stdout ¶
Stdout returns the pipe standard output is hooked up to. It's expected that the client will continuously drain the pipe if standard output is requested. The pipe will be closed once Wait returns.
func (*Exec) Wait ¶
Wait synchronously waits for the process to complete and will close the stdio pipes afterwards. This should only be called once per Exec object.
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 WithDir ¶
WithDir will use `dir` as the working directory for the process.
func WithEnv ¶
WithEnv will use the passed in environment variables for the new 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.
func WithStdio ¶
WithStdio will hook up stdio for the process to a pipe, the other end of which can be retrieved by calling Stdout(), stdErr(), or Stdin() respectively on the Exec object. Stdio will be hooked up to the NUL device otherwise.
func WithToken ¶
WithToken will run the process as the user that `token` represents.
Source Files ¶
- Version
- v0.9.9
- Published
- Mar 15, 2023
- Platform
- windows/amd64
- Imports
- 10 packages
- Last checked
- 1 hour ago –
Tools for package owners.