Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
STDOUT redirect fails in JRuby #4855
Consider the following irb session in MRI ruby:
At this point the the irb session appears to lock up, but it isn't really...
Into the irb session I will type:
But I will not see that I typed it here, nor will I see the output. Where is it?
Let us try JRuby:
JRuby will not create the file, MRI ruby does... I will do this:
Why aren't the two consistent?
There's two possibilities.
The first is due to differences in how IO is implemented on Windows versus on UNIX in JRuby. Because Windows POSIX is a little spotty in places, we need to use win32 functions to emulate Ruby behavior. We have not done this work yet. It could affect reopening stdio streams because on Windows they just wrap the ones the JDK provides, rather than being true native streams.
The second is due to our implementation of Readline, which currently uses a Java library called jline. Unfortunately this library takes over the stdio streams, breaking code like yours that wants to be in IRB and still redirect stdio.
On my macos system, your code appeared to work just fine, which makes me think it's not directly a jline problem.
Apologies if I didn't mention it, but yes this problem seems exclusive to windows. It is part of a larger problem. We have a Sinatra application that runs fine on Mac and Linux (using these APIS). On windows these APIS cause the application to just die. No Exceptions, just death...
Again apologies for my lack of clarity...
The Sinatra app runs in MRI ruby. When I bring it up it does it's initial babbling and then it just dies, without any exception, but only on Windows. Mac and Linux users have no problems. I begin to suspect it was the 'STDOUT.reopen' that was causing the issues. Out of curiosity, I tried it in JRuby. When JRuby returned:
and MRI Ruby appeared to lock up I thought I had found the first instance of a bug on Windows MRI Ruby that JRuby could handle. It took further digging before I realized what was going on. It motivated the diff (I will place it last) where I pulled out those redirects. It results in the Sinatra app working on Windows, Linux, and Mac. Again, this app runs via MRI. I just thought I should write up the JRuby bug. Perhaps I stumbled upon a case where two wrongs make a right.