Win32/Process when create a process, how to pass data

I am working on moving a server code from Linux to Window XP. I need
make original Process.fork call work on Windows XP. I tried two
I have simplified the code.

Approach 1: keep original fork method:

require ‘rubygems’
require ‘socket’
require 'win32/process

socket =‘localhost’, 12345)

pid = Process.fork {puts socket.inspect.to_s}
puts ‘byb’

when I run the script, it complained the ipaddr/port has been used,
which we do not have problem with Linux. I need the TCPserver can be
accessed by all subprocess. I tried make socket as global variable
$socket. It does not work.
Then I tried to use Process.create() with inherit set to true, like

Approach 2:

require ‘rubygems’
require ‘socket’
require ‘win32/process’

SERVER_OPTIONS = ‘-c’ # indicate it will be a child process
SUBPROC_NAME = '“C:\ruby\bin\ruby.exe” ’ +
‘"-IC:/myworkspace/SSMSProject/Source/ruby" "’ + File.expand_path($0) +

if not ARGV.include?(’-c’)
socket =‘localhost’, 12345)
pid = Process.create(
:app_name => SUBPROC_NAME,
:inherit => true
puts “hello from new process”
puts socket.inspect.to_s
puts ‘byb’

for this approach, I don’t have problem to let it run. but the child
process cannot access socket.

I am new for Ruby with Win32. Can anyone help me? Thank you in advance!


BTW I installed win32-process (0.5.9)

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