If I am running IRB and I use the method mentioned here http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-60 to return the ruby version, it works fine.
irb(main):001:0> %x{ruby -v}
=> "ruby 1.9.2p290 (2011-07-09) [i386-mingw32]\n"
But when I try to do the same thing in IRB with Java, I can see it printing to screen but it does not return.
irb(main):002:0> %x{java -version}
java version "1.6.0_27"
Java(TM) SE Runtime Environment (build 1.6.0_27-b07)
Java HotSpot(TM) 64-Bit Server VM (build 20.2-b06, mixed mode)
=> ""
What method is Java using to output to the console, and how can I capture it for use inside of a ruby/rails program?
java -version > test.txtin bash results in the java info being printed to the screen and nothing going intotest.txt.%xcaptures STDOUT only. The problem is the stream you want to capture isn't STDOUT, it's STDERR. See my answer how to deal with it simply. And, it's not a case of being Ruby-friendly, it's a case of needing to know how to work with the command-line.