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

Discussion in 'Ruby' started by Qi Lu, Jul 14, 2008.

  1. Qi Lu

    Qi Lu Guest

    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-forum.com/.
     
    Qi Lu, Jul 14, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RL
    Replies:
    2
    Views:
    599
  2. Java and Swing
    Replies:
    1
    Views:
    682
    Chris Lambacher
    Oct 24, 2005
  3. Tim Golden
    Replies:
    0
    Views:
    442
    Tim Golden
    Oct 21, 2005
  4. Mike Stead
    Replies:
    3
    Views:
    271
    Roger Pack
    Mar 25, 2010
  5. Shea Martin
    Replies:
    1
    Views:
    115
    Paul Lalli
    Jul 12, 2005
Loading...

Share This Page