#!/usr/bin/env ruby -w
require "open3"
require "drb/drb"
require "thread"
class CommandRunner
def initialize(command)
@stdin, @stdout, @stderr = Open3.popen3(command)
end
def send_input(input)
@stdin.puts(input)
end
def get_output
@stdout.gets
end
def get_errors
@stderr.gets
end
end
DRb.start_service "druby://:2001", CommandRunner.new('/usr/local/bin/R --no-save --slave')
puts DRb.uri
DRb.thread.join
test_client.rb
#!/usr/bin/env ruby -w
require 'drb/drb'
DRb.start_service
ro = DRbObject.new(nil, "druby://#{`uname -n`.chomp}:2001")
ro.send_input("x=5")
ro.send_input("print(x)")
puts ro.get_output
##
Run the test_server.rb, then run test_client.rb in another terminal