executable

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultMemoryLimitInBytes int64 = 2 * 1024 * 1024 * 1024

DefaultMemoryLimitInBytes is the default memory limit (2GB)

Variables

View Source
var ErrMemoryLimitExceeded = errors.New("process exceeded memory limit")

ErrMemoryLimitExceeded is returned when a process exceeds its memory limit

Functions

This section is empty.

Types

type Executable

type Executable struct {
	// Path is the path to the executable.
	Path string

	// TimeoutInMilliseconds is the maximum time the process can run.
	TimeoutInMilliseconds int

	// MemoryLimitInBytes sets the maximum memory the process can use (Linux only).
	// If exceeded, the process will be killed and an error will be returned.
	// Defaults to 2GB. Set to 0 to disable memory limiting.
	MemoryLimitInBytes int64

	// ShouldUsePty controls whether the executable's standard streams should be set to PTY instead of pipes.
	ShouldUsePty bool

	// WorkingDir can be set before calling Start or Run to customize the working directory of the executable.
	WorkingDir string

	// Process is the os.Process object for the executable.
	// TODO: See if this actually needs to be exported?
	Process *os.Process
	// contains filtered or unexported fields
}

Executable represents a program that can be executed

func NewExecutable

func NewExecutable(path string) *Executable

NewExecutable returns an Executable

func NewVerboseExecutable

func NewVerboseExecutable(path string, loggerFunc func(string)) *Executable

NewVerboseExecutable returns an Executable struct with a logger configured

func (*Executable) Clone

func (e *Executable) Clone() *Executable

func (*Executable) HasExited

func (e *Executable) HasExited() bool

func (*Executable) Kill

func (e *Executable) Kill() error

Kill terminates the program

func (*Executable) Run

func (e *Executable) Run(args ...string) (ExecutableResult, error)

Run starts the specified command, waits for it to complete and returns the result.

func (*Executable) RunWithStdin

func (e *Executable) RunWithStdin(stdin []byte, args ...string) (ExecutableResult, error)

RunWithStdin starts the specified command, sends input, waits for it to complete and returns the result.

func (*Executable) SendLine

func (e *Executable) SendLine(line string) error

SendLine writes a line to the process's stdin (for interactive mode). Automatically appends a newline character.

func (*Executable) Start

func (e *Executable) Start(args ...string) error

Start starts the specified command but does not wait for it to complete.

func (*Executable) Wait

func (e *Executable) Wait() (ExecutableResult, error)

Wait waits for the program to finish and returns the result.

func (*Executable) WriteStdin

func (e *Executable) WriteStdin(data []byte) error

WriteStdin writes data to the process's stdin (for interactive mode). The process must be started with Start() first.

type ExecutableResult

type ExecutableResult struct {
	Stdout   []byte
	Stderr   []byte
	ExitCode int
}

ExecutableResult holds the result of an executable run

Jump to

Keyboard shortcuts

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