Reopening STDIN for writing

Hello guys!
I’m developing FastCGI application, where data is transfered through
STDIN. The application works perfectly well in both MRI 1.9.2 and 1.8.7.
In order to reopen STDIN for writing I use the following code:

@socket = IO.new( $stdin.fileno, ‘w+b’ )

However in JRuby I get exception, stating that $stdin.fileno is “Invalid
file descriptor”.
Could you please suggest how to re-open STDIN for writing in JRuby.

If it matters, I use Windows 7 64-bit, JRuby version is 1.6.2, 64-bit.

Thank you in advance.