Hey Guys,
Since fork is not implimented in Windows, how do you spawn subprocesses
in Windows? Does anyone have a good (Cross Platform) solution besides
Ruby Threads?
Sonny.
···
--
Posted via http://www.ruby-forum.com/.
Hey Guys,
Since fork is not implimented in Windows, how do you spawn subprocesses
in Windows? Does anyone have a good (Cross Platform) solution besides
Ruby Threads?
Sonny.
--
Posted via http://www.ruby-forum.com/.
Here's something that I use as part of my test support package for IOWA. It's used primarily to provide a cross platform method for doing fork & execs of processes for testing, but could, with a little TLC, be made more general.
It depends on win32/process (By Daniel Berger, available on rubyforge or via "gem install win32-process") to create processes on Windows.
module IWATestSupport
def self.create_process(args)
@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."
end
cwd = Dir.pwd
Dir.chdir args[:dir]
pid = Process.create(:app_name => args[:cmd].join(' '))
Dir.chdir cwd
end
pid
end
end
Kirk Haines
On Sun, 4 Feb 2007, Sonny Chee wrote:
Since fork is not implimented in Windows, how do you spawn subprocesses
in Windows? Does anyone have a good (Cross Platform) solution besides
Ruby Threads?
gem install systemu
http://codeforpeople.com/lib/ruby/systemu/
http://codeforpeople.com/lib/ruby/systemu/systemu-1.0.0/README
-a
On Sun, 4 Feb 2007, Sonny Chee wrote:
Hey Guys,
Since fork is not implimented in Windows, how do you spawn subprocesses
in Windows? Does anyone have a good (Cross Platform) solution besides
Ruby Threads?Sonny.
--
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama
Sonny Chee wrote:
Hey Guys,
Since fork is not implimented in Windows, how do you spawn subprocesses
in Windows? Does anyone have a good (Cross Platform) solution besides
Ruby Threads?
It can be as simple as this:
Thread.new do
system "myprogram.exe arg arg"
end
This doesn't block your ruby process, and the thread lives until the program finishes. If you want the program to start and keep running (possibly outliving the ruby process), just use this:
system "start myprogram.exe"
or, to open a file in an application:
system "start msword-file.doc"
(Hope I'm remembering that right, I'm not on windows now to test.)
This is not cross platform, but you can wrap it in something to make it so.
There is also a kinda-sorta fork in one of the win32 utils.
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407