Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: arton Tajima
RE: Redirecting Rjb Output [ reply ]  
2011-10-25 15:32
Hi,

You can callt System.setOut with Java's (Rjb proxied) object. It's affect only for Java world vice versa if you set $stdout = File.new('blabla', 'w') only affected in Ruby world.

ex)
public class A {
public static void hello() {
System.out.println("hello");
}
}

----
# aa.rb
require 'rjb'
A = Rjb::import('A')
JSystem = Rjb::import('java.lang.System')
JPrintStream = Rjb::import('java.io.PrintStream')
JFile = Rjb::import('java.io.File')
p = JPrintStream.new(JFile.new('hello.txt'))
JSystem.setOut(p)
A.hello

$ ruby aa.rb
$ cat hello.txt
hello

Cheers.

By: Nicolas Vetel
RE: Redirecting Rjb Output [ reply ]  
2011-10-25 14:29
Thank you for you're answer.

That's not what I want to do. Here is my situation. I use a java class from which I don't have the sources, and which is very verbose. The result is that when I use it in rails, I often get polluted with many logs in console, or when executing rspec.

The problem is that I don't have much documentation about it and don't know how to shut down logs from that class. I though about capturing output from it with a special method that redirect temporarily the output to nothing, I've already done that in pure ruby.

In that case it doesn't work because the output seems to be different. I don't have any idea where the output my java class uses is so I wondered maybe I can simply redirect the Rjb output from the standard rails or ruby output.

By: arton Tajima
RE: Redirecting Rjb Output [ reply ]  
2011-10-25 14:09
Hi,

I'm not sure what you want to do.

//
class A {
static void hello() {
System.out.println("hello");
}
}

then:
# a.rb
require 'rjb'
A = Rjb::import('A')
A.hello

$ruby a.rb >hello.txt

Redirection was setup by shell (command prompt).




By: Nicolas Vetel
Redirecting Rjb Output [ reply ]  
2011-10-25 13:17
I need to redirect the output of a java class from my ruby standard output to a file.

Unfortunately, redirecting STDOUT from the ruby environment doesn't work.

I also tried to redirect the standard output of he JVM (System.setOut) but I style have messages I don't want in my console but in a file.

Does anyone knows how I could possibly redirect output from a java class to a file ?

Thank youy very much for your help.