I'm doing some crazy things at the moment, basically calling JRuby from a Ruby script on a Windows 2000 system. I'm doing this because there are a bunch of JRuby scripts that I want to run sequentially, and I also want to check for errors after each run, so what better way to invoke them and look for resulting errors than with Ruby, especially on a Windows system? :)
Unfortunately this creates a slight problem, at least on the Windows 2000 PC I'm currently using. I don't understand the error output yet, but as you can see from the following
irb output I can't invoke JRuby from Ruby like this on the Windows system:
irb(main):008:0> `jruby foo2.rb` Errno::ENOEXEC: Exec format error - jruby foo2.rb from (irb):8:in ``' from (irb):8
As you can see that leads to the dreaded "Errno::ENOEXEC: Exec format error" error message from hell.
Instead, I just learned that I have to invoke JRuby using the full name of the jruby command file, which is really
jruby.bat. With this slight change I call my jruby script like this:
irb(main):009:0> `jruby.bat foo2.rb` => "foo2\n"
And yes, that's all
foo2.rb does, is print the string "foo2", so this works. So if you see the dreaded "Errno::ENOEXEC: Exec format error" error message you may have to be more explicit in how you refer to the system program you're trying to run.
Speaking of the word "system", I had a similar problem trying to run jruby by invoking ruby's
system method. Again using
irb to demonstrate the problem, calling jruby as shown below causes the system method to return
irb(main):001:0> system("jruby foo2.rb") => false
But adding the ".bat" extension to the jruby file works, as shown here:
irb(main):002:0> system("jruby.bat foo2.rb") foo2 => true
Notice that the
system method returns
true when the system call succeeds, and
false when it does not succeed.