From: Charles Oliver Nutter Date: 2011-03-06T08:04:03+09:00 Subject: Re: [ANN] posix-spawn 0.3.0 -- first public release (codename, "tigers blood") On Sat, Mar 5, 2011 at 4:16 AM, Ryan Tomayko wrote: > On Sat, Mar 5, 2011 at 12:07 AM, Ryan Tomayko wrote: >> Yes. I experimented with using spoon for JRuby support in Grit some >> time ago. Unfortunately, a large number of posix_spawn() features >> require real OS file descriptors and there was no standard/supported >> way of retrieving them for most standard Java stream types. > > Turns out I had some of that work laying around: > > https://github.com/rtomayko/spoon/compare/spawn_file_actions > > I was able to make posix_spawn_file_actions_adddup2() and > posix_spawn_file_actions_addclose() calls but running the test fails > with: > >    $ ruby lib/spoon.rb >    _posix_spawn_file_actions_init => 0 >    /bin/echo: write: Bad file descriptor >    read: ... > If you can describe a method for retrieving real fds under JRuby > (especially IO objects returned from open() and IO.pipe()), I don't > see any reason why we couldn't have an FFI based implementation with > only a little more work. As you discovered, in JRuby IO.fileno is simulated. This is mostly because the JVM does not provide us a way to work with file descriptors directly; everything is wrapped in a Channel or an Input/OutputStream, and determining the real fd (if one exists) is tricky. However, this is a feature many people have asked for, since many native calls need a real file descriptor. I'll look into it and see if there's a way we can provide real file descriptor values somehow. - Charlie