Andrew Grimm Andrew Grimm - 1 year ago 75
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,
would be used on b.rb, but if you just used
ruby a.rb
on the original,
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

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

Answer Source

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.]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download