In golang having an instance of io.ReadWriteCloser
how to obtain its representation (kind of proxy) as an instance of *os.File
(E.g. to be provided for exec.Cmd.ExtraFiles
)
The first is coming to a mind is to use os.Pipe
approach. Still such a stub would be unidirectional (read or write only).
So how to completely represent io.ReadWriteCloser
as an *os.File
E.g.
func something(stream io.ReadWriteCloser) { cmd := exec.Command("comm") var wrapped *os.File = wrappAsFile(stream) // How this could be achieved? cmd.ExtraFiles := []*File{wrapped}}
Simplified solution I can see would be something like the following. Still (as I mentioned it before) it covers only a Reader flow.
func something(stream io.ReadWriteCloser) { cmd := exec.Command("comm") r, w, _ := os.Pipe() go func() { io.Copy(w, stream) w.Close() }() cmd.ExtraFiles := []*File{r}}
Thx