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

Stdioimplements FromRawFd, which allows me to create one from any file descriptor. (In my case, I want to use pipes.) This is exactly what I need, but my problem is that the stdin()/ stdout()/ methods stderr()take their argument Stdioby value. This means that when an object Commandgoes out of scope, all its fd are closed. Is there a way to pass fd to a child process by reference so that it is still available in the parent process after the child is complete? Right now, I decided to just name libc::dup()for each child what doesn't seem big.

+4
source share
1 answer

There is currently no better solution, alas. However, the correct solution would be a method Command::into_io(self) -> (Option<StdIo>, Option<StdIo>, Option<StdIo>)that deconstructs Commandto return stdin, stdout, and stderr, if available.

I added issue to add this feature.

+2
source

All Articles