exec

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: GPL-2.0, GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package exec provides helpers for running system commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec added in v0.1.5

func Exec(command string, args ...string) error

Exec replaces the current process with the given command. On success it never returns; the calling process is replaced entirely. Returns an error only if the exec syscall itself fails.

func Has

func Has(command string) bool

Has reports whether a command exists in PATH.

func Run

func Run(command string, args ...string) error

Run executes a command with inherited stdio. Returns an error if the exit code is non-zero.

func RunCode

func RunCode(command string, args ...string) int

RunCode executes a command with inherited stdio and returns the exit code. Use this when the caller needs to branch on specific exit codes.

func RunQuiet added in v0.1.7

func RunQuiet(command string, args ...string) error

RunQuiet executes a command, discarding stdout but capturing stderr. If the command fails, the returned error includes the stderr output so you know why it failed.

func RunSilent

func RunSilent(command string, args ...string) error

RunSilent executes a command, discarding stdout and stderr. Returns an error if the exit code is non-zero.

func Sh

func Sh(command string) string

Sh executes a shell string via "sh -c" and returns trimmed stdout. Errors are silently ignored — use RunCapture if you need them.

Types

type Result

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

Result holds the output of a captured command.

func RunCapture

func RunCapture(command string, args ...string) (Result, error)

RunCapture executes a command and captures stdout and stderr.

func RunCaptureWithStdin added in v0.1.7

func RunCaptureWithStdin(command string, stdinData string, args ...string) (Result, error)

RunCaptureWithStdin executes a command, writes data to its stdin, and captures stdout/stderr. Useful for commands that require interactive input (like hashing passwords) without exposing the input in the process list (ps aux).

Jump to

Keyboard shortcuts

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