Any way to give a file descriptor to a child process, without closing it?

Viewed 238

The Stdio type implements FromRawFd, which lets me build one out of any file descriptor. (In my case, I want to use pipes.) That's exactly what I need, but my problem is that the stdin()/stdout()/stderr() methods take their Stdio argument by value. That means that when the Command object goes out of scope, all its fd's get closed. Is there any way to give an fd to a child process sort of by reference, so that it's still available in the parent process after the child is done? Right now I've settled for just calling libc::dup() for each child, which doesn't seem great.

1 Answers
Related