Andrew Grimm Andrew Grimm - 26 days ago 10
Ruby Question

Running another ruby script from a ruby script

In ruby, is it possible to specify to call another ruby script using the same ruby interpreter as the original script is being run by?

For example, if a.rb runs b.rb a couple of times, is it possible to replace

system("ruby", "b.rb", "foo", "bar")


with something like

run_ruby("b.rb", "foo", "bar")


so that if you used
ruby1.9.1 a.rb
on the original,
ruby1.9.1
would be used on b.rb, but if you just used
ruby a.rb
on the original,
ruby
would be used on b.rb?

I'd prefer not to use shebangs, as I'd like it to be able to run on different computers, some of which don't have
/usr/bin/env
.

Edit: I didn't mean
load
or
require
and the like, but spawning new processes (so I can use multiple CPUs).

Answer

Avdi Grimm wrote a series of articles on the Devver blog about different ways to start Ruby subprocesses last summer:

[Note: it appears that part 4 hasn't been published yet.]

Comments