The types don't quite line up here. Specifically,
cmd.StdoutPipe
returns an io.ReadCloser
whereas
pipeR.Read
is expecting an []byte
as input.
I believe you are ultimately looking to utilize the Read and Write functions of the os package to accomplish your task as shown below:
package main
import (
"log"
"os"
"os/exec"
)
func main() {
cmd := exec.Command("command", "-o", "-")
pipeR, pipeW, _ := os.Pipe()
cmd.ExtraFiles = []*os.File{
pipeW,
}
cmd.Start()
cmdstdout, err := cmd.StdoutPipe()
if err != nil {
log.Printf("pipeThruError: %v
", err)
os.Exit(1)
}
buf := make([]byte, 100)
cmdstdout.Read(buf)
pipeR.Close()
pipeW.Close()
fd3 := os.NewFile(3, "/proc/self/fd/3")
fd3.Write(buf)
fd3.Close()
}