streamexec

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: MIT Imports: 6 Imported by: 3

Documentation

Overview

Package streamexec provides integrations with os/exec to stream command output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start added in v0.9.0

func Start(cmd *exec.Cmd, modes ...StreamMode) (*streamline.Stream, error)

Start attaches a streamline.Stream to the command and starts it. It returns an error if the command fails to start. If the command successfully starts, it also starts a goroutine that waits for command completion and stops the pipe appropriately.

If no modes are provided, the default stream mode is Combined. If multiple modes are provided, they are all included.

Instead of using cmd.Wait() for command completion, callers should read the returned Stream until completion to indicate if the command has exited.

Before consuming the Stream, the caller can configure the Stream as a normal stream using e.g. WithPipeline.

Output piping is handled by buffers created by streamline/pipe.NewStream(...).

Types

type StreamMode

type StreamMode int

StreamMode indicates what output(s) to attach.

const (
	// Combined streams both Stdout and Stderr. It is the default stream mode.
	Combined StreamMode = Stdout | Stderr

	// Stdout only streams cmd.Stdout.
	Stdout StreamMode = 1 << iota
	// Stderr only streams cmd.Stderr.
	Stderr

	// ErrWithStderr collects Stderr output and includes it in the returned error from
	// Cmd.Start(). Best used with the Stdout StreamMode to avoid duplicating stderr
	// output in the stream and in the returned error.
	ErrWithStderr
)

Jump to

Keyboard shortcuts

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