Redirecting java stdout to a JRuby socket

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs