zstdzgo.at/zstd/zexec Index | Files

package zexec

import "zgo.at/zstd/zexec"

Package zexec runs external commands.

Index

Functions

func Readlines

func Readlines(cmd *exec.Cmd) (<-chan Output, error)

Readlines calls cmd.Start sends every line of output on the returned channel.

Example usage:

cmd := exec.Command("long-running-process")
ch, err := zexec.Readlines(cmd)

for {
	line, ok := <-ch
	if !ok {
		break
	}
	if line.Error != nil {
		fmt.Fprintln(os.Stderr, "error reading:", line.Error)
		break
	}

	fmt.Println(line)
}

Types

type Output

type Output struct {
	Text   string // Read text, excluding the end delimiter.
	Stderr bool   // Text was sent on stderr.

	// Errors reading the process stdout/stderr; sent only once, and will stop
	// reading after an error.
	Error error
}

func (Output) String

func (o Output) String() string

Source Files

zexec.go

Version
v0.0.0-20240930202209-a63c3335042a (latest)
Published
Sep 30, 2024
Platform
linux/amd64
Imports
4 packages
Last checked
2 days ago

Tools for package owners.