You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The os/exec package currently only supports mapping io.Reader and io.Writer objects to Stdin, Stdout, and Stderr. It would be nice if Cmd supported adding additional readers and writers for other file descriptors. For example, I would like to have FFmpeg split an Ogg stream from Stdin into two separate io.Writers (one assigned to Stdout and the other on FD 3). I can do this by creating my own pipe and spinning up a goroutine to do the io.Copy, but that functionality is already built into os/exec. It just needs to be exposed in the public API. Perhaps something like:
That works the same way as StdinPipe/StdoutPipe but also returns the fd number that will be available in the forked process.
There are some issues with this design:
If you want to use exec.Command() and pass the fd number as argument you will need to modify Cmd.Args field afterwards.
What happens if ExtraInPipe/ExtraOutPipe is used but Start() is never called? enough with os.Pipe()newFile close finalizer for cleanup? same issue with StdinPipe/StdoutPipe i guess?
Might be unintuitive that the public ExtraFiles field gets modified?
I also tried changing Cmd.ExtraFiles to []interface{} but it felt weird and might not be backwards compatible?
@bradfitz would this be something worth adding to the standard library? some other nicer design possible?
The
os/exec
package currently only supports mappingio.Reader
andio.Writer
objects toStdin
,Stdout
, andStderr
. It would be nice ifCmd
supported adding additional readers and writers for other file descriptors. For example, I would like to have FFmpeg split an Ogg stream fromStdin
into two separateio.Writer
s (one assigned toStdout
and the other on FD 3). I can do this by creating my own pipe and spinning up a goroutine to do theio.Copy
, but that functionality is already built intoos/exec
. It just needs to be exposed in the public API. Perhaps something like:The text was updated successfully, but these errors were encountered: