Forum: JRuby redirecting java stdout to a JRuby socket

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Gergely Nagy (Guest)
on 2013-11-04 10:39
(Received via mailing list)
Hi Gurus,

Is there a way to redirect java.lang.System.out to a RubySocket's

I was trying this with a simple tcp server, where I first had a
$stdout = socket

After which a plain puts() worked and dumped stuff on the other side of
Then, tried to do the same with some java code, calling
java.lang.System.setOut() with these:

a) new_java_out =$stdout.to_outputstream,

b) new_java_out = JRuby.runtime.getOutputStream()

# so that this would work:
System.out.println("hi there")

The problem was I didn't see anything on the other side, debugging into
this a bit, I see some IOException "not opened for writing", with the
following trace:

ChannelStream.bufferedWrite(ByteBuffer) line: 1112
ChannelStream.access$700(ChannelStream, ByteBuffer) line: 62
ChannelStream$OutputStreamAdapter.write(byte[], int, int) line: 1640
PrintStream.write(byte[], int, int) line: 480

Note that a doing the above with a file in place of socket worked fine.
Here's the full source:

Ideas are welcome. Is this a bug in my code or jruby? I was surprised to
see an output stream "not opened for writing".

Thank you.
This topic is locked and can not be replied to.