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

Q

Qi Lu

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
approaches:
I have simplified the code.

Approach 1: keep original fork method:

require 'rubygems'
require 'socket'
require 'win32/process

socket = TCPServer.new('localhost', 12345)

pid = Process.fork {puts socket.inspect.to_s}
Process.wait
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) +
'" ' + SERVER_OPTIONS

if not ARGV.include?('-c')
socket = TCPServer.new('localhost', 12345)
pid = Process.create(
:app_name => SUBPROC_NAME,
:inherit => true
)
else
puts "hello from new process"
puts socket.inspect.to_s
end
Process.wait
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!

Qi

BTW I installed win32-process (0.5.9)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top