subprocess

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package subprocess contains code to exec subprocesses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustPipeTo

func MustPipeTo(ctx context.Context, dryRun bool, stdin []byte, argv0 string, args ...string)

MustPipeTo is like PipeTo but logs and exits on failure.

func MustPipeline

func MustPipeline(ctx context.Context, dryRun bool, stages ...[]string)

MustPipeline is like Pipeline but logs and exits on failure.

func MustRun

func MustRun(ctx context.Context, dryRun bool, argv0 string, args ...string)

MustRun is like Run but logs and exits on failure.

func MustRunTolerant

func MustRunTolerant(ctx context.Context, dryRun bool, argv0 string, args ...string)

MustRunTolerant is like RunTolerant but logs and exits on failure.

func PipeTo

func PipeTo(ctx context.Context, dryRun bool, stdin []byte, argv0 string, args ...string) error

PipeTo runs the command represented by argv, piping stdin to its standard input. The argv0 resolves through the deps.All allowlist just like Run.

When dryRun is true, PipeTo prints a round-trippable shell snippet to stdout: the command followed by a heredoc containing stdin, using a random heredoc terminator to avoid collisions with the payload. Pasting the output into a shell reproduces the effect of a live run.

func Pipeline

func Pipeline(ctx context.Context, dryRun bool, stages ...[]string) error

Pipeline runs a shell-style pipeline of commands wired with pipes. Each stage is an argv slice whose first element must be a command name in deps.All. The first stage's stdin is not connected; the last stage's stdout goes to env.Stdout; every stage's stderr goes to env.Stderr.

When dryRun is true, Pipeline prints a single shell line with the stages joined by " | ".

In live mode, all stages are started concurrently and connected via io.Pipe instances. When a stage exits, its downstream pipe writer is closed (thus sending EOF to the next stage) while its upstream reader is closed (thus sending broken-pipe to the previous stage). The returned error joins stage errors using errors.Join.

This function panics if any stage contains zero entries.

The combined pipeline stdout is the stdout exposed by *testable.Environ while the combined pipeline stdin is /dev/null.

func Run

func Run(ctx context.Context, dryRun bool, argv0 string, args ...string) error

Run runs the command represented by the given argv.

The argv0 must be a bare command name in deps.All; Run resolves it to an absolute path via deps.LookPath before execution.

When the dryRun argument is true the command is not executed but rather the command that would be executed is printed on stdout. Dry-run does not resolve or enforce the allowlist because it has no side effects.

func RunTolerant

func RunTolerant(ctx context.Context, dryRun bool, argv0 string, args ...string) error

RunTolerant is like Run but suppresses non-zero exit codes, mirroring the shell idiom "cmd || true". Setup errors (command not in the allowlist, LookPath failure) are still reported.

When dryRun is true, the rendered shell line includes a trailing "|| true".

Types

This section is empty.

Jump to

Keyboard shortcuts

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