Creating child processes in Windows?

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.

On Sun, 4 Feb 2007, Sonny C. 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?

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 B., 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 H.

On Sun, 4 Feb 2007, Sonny C. 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.

gem install systemu

http://codeforpeople.com/lib/ruby/systemu/
http://codeforpeople.com/lib/ruby/systemu/systemu-1.0.0/README

-a

Sonny C. 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.