Re: Spawning daemon processes
- From: khaines@xxxxxxxxx
- Date: Fri, 1 Sep 2006 02:41:33 +0900
On Fri, 1 Sep 2006, Thiago Arrais wrote:
Is there any idiomatic way of doing that in Ruby that is platform independent?
I'd just use Daniel Berger's win32utils:
http://rubyforge.org/projects/win32utils/
You need win32-process (which needs windows-pr) out of there, and then you can easily use create_process on Windows. Here's one way that I use it to provide a method for spawning new processes that works where fork exists and on Windows, as well.
module IWATestSupport
def self.create_process(args)
# Takes a hash with two keys, :cmd and :dir.
# :cmd is the command to execute, and :dir is the directory to
# execute the command from.
args[:cmd] = [args[:cmd]] unless args[:cmd].is_a?(Array)
@fork_ok = true unless @fork_ok == false
pid = nil
begin
raise NotImplementedError unless @fork_ok
unless pid = fork
Dir.chdir args[:dir]
exec(*args[:cmd])
end
rescue NotImplementedError
@fork_ok = false
begin
require 'rubygems'
rescue Exception
end
begin
require 'win32/process'
rescue LoadError
raise "Please install win32-process.\n'gem install win32-process' or http://rubyforge.org/projects/win32utils"
end
cwd = Dir.pwd
Dir.chdir args[:dir]
pid = Process.create(:app_name => args[:cmd].join(' '))
Dir.chdir cwd
end
pid
end
end
IWATestSupport.create_process({:dir => 'TC_CGI_Adaptor',
:cmd => [ruby,'-I../../../src','webrick.rb']})
There are a lot of very nice things in Dan's win32utils.
Kirk Haines
.
- References:
- Spawning daemon processes
- From: Thiago Arrais
- Spawning daemon processes
- Prev by Date: Re: Hal Fulton Interview
- Next by Date: Re: Hal Fulton Interview
- Previous by thread: Spawning daemon processes
- Index(es):
Relevant Pages
|