/go-cmdio

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

Primary LanguageGoMIT LicenseMIT

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