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

**URL:** <https://www.ruby-forum.com/t/win32-process-when-create-a-process-how-to-pass-data/143065>\
**Category:** Ruby\
**Created:** [July 14, 2008, 9:43pm UTC](https://www.ruby-forum.com/t/win32-process-when-create-a-process-how-to-pass-data/143065 "2008-07-14T21:43:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![qilu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/e79b87/32.png) [@qilu](https://www.ruby-forum.com/u/qilu)\
**Post date:** [July 14, 2008, 9:43pm UTC](https://www.ruby-forum.com/t/win32-process-when-create-a-process-how-to-pass-data/143065/1 "2008-07-14T21:43:15Z")

</div>

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)
