Re: [jruby-user] Re: rescue error?

John Joseph Bachir <[email protected]> Sat, 21 Mar 2015 14:00:04 -0400
Newsgroups gmane.comp.lang.jruby.user
Message-ID <CAOf2Z5t0GBGZFkP5sHWNUYXe7BDUA_-=BHm+0Y1=3HAxkHTH-A@mail.gmail.com>
open4 (gem on mri, native on jruby) will raise an error if it doesn't find
the executable. try something like this:

if IO.respond_to?(:popen4) #jruby
  def open4(*args)
    IO.popen4(*args)
  end
else # mri
  require 'open4'
end

begin
  open4("monkey")
rescue
  print "monkey not available"
end




On Sat, Mar 21, 2015 at 12:13 PM, Jabari Z. <[email protected]> wrote:

> Hey Keith, thanks.
>
> Doing something like this:
>
> if system('which factor'); puts 'Yes factor' else 'No factor' end
>
> is much cleaner and transportable.
>
> I tested it on my system with MIR (1.8.7, 2.1.2, 2.2.1), JRuby-1.7.19
> and Rubinius-2.5.2, and there were no problems. I'll try it later on my
> Win7 system with Rubyinstaller rubies.
>
> FYI, I started out using the RUBY_PLATFORM value to check against, but
> soon realized I would have to know if 'factor' runs on all the possible
> ruby platforms to make if universally transportable, so I started
> checking directly for 'factor' being on a platform. In Unix 'factor' has
> been standard since 1974, and in Linux and BSD since their inception, so
> I'm not too concerned about possible false positives on other platforms.
>
> https://en.wikipedia.org/wiki/Factor_(Unix)
>
> The still open question, though, is JRuby's non-conformist to MRI
> behavior handling rescue in the original example. This can obviously
> have catastrophic consequences for people expecting their MRI code to
> operate the same on JRuby.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>