Skip to content

Instantly share code, notes, and snippets.

@lucasdavila
Created September 12, 2012 02:51
Show Gist options
  • Select an option

  • Save lucasdavila/3703950 to your computer and use it in GitHub Desktop.

Select an option

Save lucasdavila/3703950 to your computer and use it in GitHub Desktop.
Calling a jruby script from a ruby script (via shell)
$jruby_bin = '/path/to/jruby/bin/jruby'
$children_script = File.join File.expand_path('.'), 'children.rb'
def call_children command = ''
full_command = "#{$jruby_bin} -r#{$children_script} -e '#{command}'"
puts "Executing command: #{full_command}"
system full_command
end
puts "Hello from parent!"
call_children "say_hello"
require 'java'
def say_hello
java.lang.System.out.println "Hello from children!"
end
Running "$ ruby parent.rb", will display:
Hello from parent!
Executing command: /path/to/jruby -r/path/to/children.rb -e 'say_hello'
Hello from children!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment