Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a Java program in Ruby and getting output

I want my Rails app to call a Java program to do some labor-intensive work. What's the best way to get the output from the Java program into Ruby? The output is text, about 60,000 chars per query.

Is there a better way than writing/reading from textfiles?

I don't want to use JRuby.

like image 947
bevanb Avatar asked May 16 '26 21:05

bevanb


2 Answers

output = %x{java your_program.java}
like image 89
SwiftMango Avatar answered May 18 '26 10:05

SwiftMango


Depends on scale. It could be worth actually setting up a messaging protocol such as RabbitMQ.

If you are just setting up a monitor or other script driven process, you could look at ruby's IO.popen, but that would still leave you parsing text streams.

like image 33
verrdon Avatar answered May 18 '26 12:05

verrdon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!