Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 634 Bytes

README.md

File metadata and controls

41 lines (30 loc) · 634 Bytes

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