Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spawn a background process in Ruby on Windows?

I am basically asking the same question as Spawn a background process in Ruby, except I need to spawn a background process in a Windows environment! Unfortunately, my research has revealed that Windows doesn't support Ruby forks (only spoons. Rimshot!).

like image 533
David Rivers Avatar asked Oct 01 '10 15:10

David Rivers


3 Answers

Charles's answer is great. I also discovered that I can utilize Windows's start, for example to execute the dir command as such:

system('start dir')

This spawns a cmd window along with the process, which is undesirable in some circumstances. However, if this is tolerable, then you don't need the win32-process dependency :)

like image 191
David Rivers Avatar answered Nov 14 '22 04:11

David Rivers


1.9.x's Process.spawn seems to work well, see the last section of http://en.wikibooks.org/wiki/Ruby_Programming/Running_Multiple_Processes

like image 43
rogerdpack Avatar answered Nov 14 '22 05:11

rogerdpack


The win32-process library, part of the Win32Utils suite, is probably what you're after.

http://win32utils.rubyforge.org/

The win32-process library adds the Process.create and Process.fork methods for MS Windows. In add addition, it provides different implementations of the wait, wait2, waitpid, and waitpid2 methods. The Process.create method allows you to create native MS Windows processes using a variety of different configuration options.

The Process.fork implementation should be considered experimental and not used in production code.

Installation: gem install win32-process

like image 13
Charles Roper Avatar answered Nov 14 '22 05:11

Charles Roper