exec

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 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

Overview

Package exec provides subprocess helpers that keep secrets out of argv.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyName = errors.New("runwithenv: executable name must not be empty")

ErrEmptyName is returned when an empty executable name is passed to RunWithEnv.

View Source
var ErrNilContext = errors.New("runwithenv: context must not be nil")

ErrNilContext is returned when a nil context is passed to RunWithEnv.

Functions

func RunWithEnv

func RunWithEnv(ctx context.Context, extraEnv map[string]string, name string, args ...string) ([]byte, error)

RunWithEnv runs name with args, injecting extraEnv into the subprocess environment. Credentials passed via extraEnv never appear in the process table (argv is the only public part of a process visible to `ps`).

The subprocess inherits the current process environment (os.Environ()) with each key in extraEnv added or overridden. Callers can therefore observe exactly which variables are being injected: they are listed in extraEnv.

Returns combined stdout+stderr and the first error encountered (context cancellation, exec failure, or non-zero exit).

Inputs:

  • ctx: cancellation/deadline; non-nil required.
  • extraEnv: map of KEY -> VALUE to inject; nil or empty map is valid.
  • name: executable name or absolute path; must be non-empty.
  • args: arguments passed to name; no credential values should appear here.

Failure modes:

  • ctx is nil: returns ErrNilContext immediately (no exec).
  • name is empty: returns ErrEmptyName immediately (no exec).
  • executable not found: exec.CommandContext returns the error from os/exec.
  • non-zero exit: error wraps the combined output for diagnosis.
  • context canceled/timed out: error reflects the context state.

Types

This section is empty.

Jump to

Keyboard shortcuts

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