Ruby subprocess

I am wanting inside of a ruby script to execute another ruby script in
a subprocess in the same manner as exec(). As first thought I
considered seeing if you can lookup the ruby executable path from
within ruby, but I couldn’t find a way of doing it. If that was the
case you could just say exec("/usr/bin/ruby " + “file.rb”).

On Sun, 25 Feb 2007, badcherry wrote:

I am wanting inside of a ruby script to execute another ruby script in
a subprocess in the same manner as exec(). As first thought I
considered seeing if you can lookup the ruby executable path from
within ruby, but I couldn’t find a way of doing it. If that was the
case you could just say exec("/usr/bin/ruby " + “file.rb”).

 require 'rbconfig'

 def which_ruby
   c = ::Config::CONFIG
   File::join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
 end

 ruby = which_ruby

 exec ruby, 'file.rb'

probably won’t work on windows since the one-click breaks (or used to
break)
rbconfig.

-a

On 25.02.2007 05:52, badcherry wrote:

I am wanting inside of a ruby script to execute another ruby script in
a subprocess in the same manner as exec(). As first thought I
considered seeing if you can lookup the ruby executable path from
within ruby, but I couldn’t find a way of doing it. If that was the
case you could just say exec("/usr/bin/ruby " + “file.rb”).

Depending on the platform you can use fork like this:

child_pid = fork do

child code

load “file.rb”
end

Process.wait(child_pid)
print "Child ", child_pid, " exited with ", $?.exitstatus, “\n”

See
http://www.ruby-doc.org/core/classes/Kernel.html#M005750
http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_threads.html

HTH

robert

On Feb 24, 10:59 pm, [email protected] wrote:

 exec ruby, 'file.rb'

probably won’t work on windows since the one-click breaks (or used to break)
rbconfig.

This will work for now, but didn’t test it on windows yet. Thanks,
much.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs