Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Win32/Process when create a process, how to pass data
Qi Lu
7/14/2008 7:39:00 PM
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)
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Win32/Process when create a process, how to pass data
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password