process

package
v0.13.0-beta3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package process provides additional utilities for launching and managing executable processes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecutableName

func ExecutableName(base, goos string) string

ExecutableName computes the name for an executable for a given base name on a specified operating system.

func FindCommand added in v0.10.0

func FindCommand(name string, paths []string) (string, error)

FindCommand searches for a command with the specified name within the specified list of directories. It's similar to os/exec.LookPath, except that it allows one to manually specify paths, and it uses a slightly simpler lookup mechanism.

func IsPOSIXShellCommandNotFound added in v0.10.0

func IsPOSIXShellCommandNotFound(state *os.ProcessState) bool

IsPOSIXShellCommandNotFound returns whether or not a process state represents a "command not found" error from a POSIX shell.

func IsPOSIXShellInvalidCommand added in v0.10.0

func IsPOSIXShellInvalidCommand(state *os.ProcessState) bool

IsPOSIXShellInvalidCommand returns whether or not a process state represents an "invalid" error from a POSIX shell.

func OutputIsWindowsCommandNotFound added in v0.10.0

func OutputIsWindowsCommandNotFound(output string) bool

OutputIsWindowsCommandNotFound returns whether or not a process' error output represents a command not found error on Windows.

func OutputIsWindowsInvalidCommand added in v0.10.0

func OutputIsWindowsInvalidCommand(output string) bool

OutputIsWindowsInvalidCommand returns whether or not a process' error output represents an invalid command error on Windows.

Types

type Stream added in v0.12.0

type Stream struct {
	// contains filtered or unexported fields
}

Stream implements io.ReadWriteCloser around the standard input/output of a process. It is "closed" by terminating the underlying process. It supports an optional "kill delay" which tells the Close method to wait (up to the specified duration) for the process to exit on its own before killing it.

func NewStream added in v0.12.0

func NewStream(process *exec.Cmd, killDelay time.Duration) (*Stream, error)

NewStream creates a new stream (io.ReadWriteCloser) by wraping a command object. It must be called before the corresponding process is started, while the resulting stream must only be used after the corresponding process is started. This function will panic if killDelay is negative.

func (*Stream) Close added in v0.12.0

func (s *Stream) Close() error

Close closes the stream by terminating the underlying process and waiting for it to exit. This is the only portable way to unblock input/output streams, as many platforms will block closure of an OS pipe if there are pending read or write operations.

If a non-negative/non-zero kill delay has been specified, then this this method will wait (up to the specified duration) for the process to exit on its own before issuing a kill request. By the time this method returns, the underlying process is guaranteed to no longer be running.

func (*Stream) Read added in v0.12.0

func (s *Stream) Read(buffer []byte) (int, error)

Read implements io.Reader.Read.

func (*Stream) SetKillDelay added in v0.12.0

func (s *Stream) SetKillDelay(killDelay time.Duration)

SetKillDelay sets the kill delay for the stream. This function will panic if killDelay is negative. This method is safe to call concurrently with Close, though if called concurrently, there is no guarantee that the new kill delay will be set before Close checks its value.

func (*Stream) Write added in v0.12.0

func (s *Stream) Write(buffer []byte) (int, error)

Write implements io.Writer.Write.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL