process

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 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 DetachedProcessAttributes added in v0.7.0

func DetachedProcessAttributes() *syscall.SysProcAttr

DetachedProcessAttributes returns the process attributes to use for starting detached processes.

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.8.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.7.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.7.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.7.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.7.0

func OutputIsWindowsInvalidCommand(output string) bool

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

Types

type Connection added in v0.7.0

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

Connection implements net.Conn 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 connection to wait (up to the specified duration) for the process to exit on its own before killing it when Close is called.

func NewConnection added in v0.7.0

func NewConnection(process *exec.Cmd, killDelay time.Duration) (*Connection, error)

NewConnection creates a new net.Conn object by wraping a command object. It must be called before the corresponding process is started. The specified kill delay period must be greater than or equal to zero, otherwise this function will panic.

func (*Connection) Close added in v0.7.0

func (c *Connection) Close() error

Close closes the process connection by terminating the underlying process and waiting for it to exit. If a non-negative/non-zero kill delay has been specified, then 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. HACK: Rather than closing the process' standard input/output, this method simply terminates the process. The problem with closing the input/output streams is that they'll be OS pipes that might be blocked in reads or writes and won't necessarily unblock if closed, and they might even block the close - it's all platform dependent. But terminating the process will close the remote ends of the pipes and thus unblocks and reads/writes.

func (*Connection) LocalAddr added in v0.7.0

func (c *Connection) LocalAddr() net.Addr

LocalAddr returns the local address for the connection.

func (*Connection) Read added in v0.7.0

func (c *Connection) Read(buffer []byte) (int, error)

Read reads from the process connection.

func (*Connection) RemoteAddr added in v0.7.0

func (c *Connection) RemoteAddr() net.Addr

RemoteAddr returns the remote address for the connection.

func (*Connection) SetDeadline added in v0.7.0

func (c *Connection) SetDeadline(_ time.Time) error

SetDeadline sets the read and write deadlines for the connection.

func (*Connection) SetKillDelay added in v0.7.0

func (c *Connection) SetKillDelay(killDelay time.Duration)

SetKillDelay changes the kill delay period set in the connection constructor. The specified kill delay period must be greater than or equal to zero, otherwise this method will panic. 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 (*Connection) SetReadDeadline added in v0.7.0

func (c *Connection) SetReadDeadline(_ time.Time) error

SetReadDeadline sets the read deadline for the connection.

func (*Connection) SetWriteDeadline added in v0.7.0

func (c *Connection) SetWriteDeadline(_ time.Time) error

SetWriteDeadline sets the write deadline for the connection.

func (*Connection) Write added in v0.7.0

func (c *Connection) Write(buffer []byte) (int, error)

Write writes to the process connection.

Jump to

Keyboard shortcuts

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