cmdio

package module
v0.0.0-...-79f871e Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: MIT Imports: 9 Imported by: 0

README

cmdio

Run an executable and provide it input/output files via io.Reader/io.Writer.

Usage

package main

import (
    "log"
    "os"
    "os/exec"
    "strings"

    cmdio "github.com/rikonor/go-cmdio"
)

func main() {
    r := strings.NewReader("Hello!")
    w := os.Stdout

    execPath := "./text-doubler"
    execArgs := []string{"INPUT", "OUTPUT"}

    tmpArgs, closeFn, err := cmdio.WrapSimple(r, w, execArgs)
    if err != nil {
        log.Fatal(err)
    }
    defer closeFn()

    cmd := exec.Command(execPath, tmpArgs...)
    if err := cmd.Run(); err != nil {
        log.Fatal(err)
    }
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloseFunc

type CloseFunc func() error

CloseFunc needs to be called to clean up resources

func Wrap

func Wrap(rs []io.Reader, ws []io.Writer, execArgs []string) ([]string, CloseFunc, error)

Wrap wraps a command such that it uses named pipes attached to the given readers and writers instead of using actual files.

func WrapSimple

func WrapSimple(r io.Reader, w io.Writer, execArgs []string) ([]string, CloseFunc, error)

WrapSimple wraps a command such that it uses named pipes attached to the given reader and writer instead of using actual files.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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