我正在使用守护进程工具包启动后台ruby进程,用于监听Amazon SQS消息。一旦接收到消息,它就会启动一个需要在JRuby中运行的Open3.popen3的子进程。在不同的ruby版本中启动子进程
后台进程需要在MRI中运行,因为守护进程工具包使用Process.daemon来守护进程。但到目前为止,我还无法强制子进程在JRuby中运行。
我使用rbenv管理红宝石版本,所以起初我以为这会工作:
Open3.popen3({"RUBY_VERSION" => "jruby-1.7.8"}, "rp5 run /path/to/sketch.rb") do |stdin, stdout, stderr, wait_thr|
# read stderr and stdout for status and error information ....
end
但是在子进程输出我得到的错误:“rbenv:JRuby的:命令未找到”
然后我跟踪了rbenv如何运行它的可执行文件,以便我可以绕过rbenv并直接在JRuby中运行rp5可执行文件。
我第一次发现该文件夹中的可执行RP5:〜/ .rbenv /版本/ JRuby的1.7.8 /斌/ RP5
#!/Users/fede/.rbenv/versions/jruby-1.7.8/bin/jruby
#
# This file was generated by RubyGems.
#
# The application 'ruby-processing' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/
version = $1
ARGV.shift
end
end
gem 'ruby-processing', version
load Gem.bin_path('ruby-processing', 'rp5', version)
然后我执行的Gem.bin_path方法找到它的可执行RP5它在呼唤。这是在宝石内:〜/ .rbenv/versions/jruby-1.7.8/lib/ruby/gems/shared/gems/ruby-processing-2.3.1/bin/rp5然后我试着运行子进程这个rp5可执行文件直接:
Open3.popen3("~/.rbenv/versions/jruby-1.7.8/lib/ruby/gems/shared/gems/ruby-processing-2.3.1/bin/rp5 run path/to/sketch.rb") do |stdin, stdout, stderr, wait_thr|
# read stderr and stdout for status and error information ....
end
但我仍然得到相同的“jruby命令未找到”错误。
然后我考察该可执行文件:
#!/usr/bin/env ruby
file = __FILE__
if test(?l, file)
require "pathname"
file = Pathname.new(file).realpath
end
require File.expand_path(File.dirname(file) + "/../lib/ruby-processing")
Processing::Runner.execute
所以确实在顶部的家当意味着这个可执行文件是使用默认的红宝石版本?
甚至可以在完全不同的ruby版本中启动子进程吗?
谢谢。