System call will try to find gems in jruby path in jruby on rails

Dear buddies,

I am using jruby on rails for rails 2.3.8. And I wanted to process the
images uploaded, for the image_voodoo and rmagick4j are both not good
enough
for our requirement. What we did is calling an external ruby script and
use
rmagick in that ruby script to handling the image processing work.

I add the code like the following:
system(“ruby ${path}/image_processing.rb filename.jpg”)

It works fine if I put image_processing.rb in the path like
/Users/stanley
on a MacOSX

But it will fail if I put the image_processing.rb inside the application
path, like /Users/stanley/Documents/codebase/imoso_code/lianyijia/script
(lianyijia is the rails app path)

The message told me it could not find the gem rmagick in jruby gem path.

Could anyone told me why or give a possible solution? For I wanted to
put
the script inside the rails app path and then I could deploy the code
simply
without define an absolute path and copy the script every time.

Best wishes,
Stanley Xu

Thanks Nick, that’s correct. I fixed the issue by the steps in your
mail.

Best wishes,
Stanley Xu

On Sun, Oct 17, 2010 at 5:43 AM, Stanley Xu [email protected] wrote:

path, like/Users/stanley/Documents/codebase/imoso_code/lianyijia/script
(lianyijia is the rails app path)

The message told me it could not find the gem rmagick in jruby gem path.
Could anyone told me why or give a possible solution? For I wanted to put
the script inside the rails app path and then I could deploy the code simply
without define an absolute path and copy the script every time.

You might be running afoul of JRuby’s built-in magic that tries to
spawn ruby scripts in process. To see if that’s the case, try changing
the system command to something like:

system("bash -c 'ruby ${path}/image_processing.rb filename.jpg'")

If so, then you can either disable in-process script launching, or use
a modified command like above. To disable inprocess launching, put

require 'jruby'
JRuby.runtime.instance_config.run_ruby_in_process = false

somewhere in your script or startup.

/Nick