I am basically asking the same question as Spawn a background process in Ruby, except I need to spawn a back开发者_运维问答ground process in a Windows environment! Unfortunately, my research has revealed that Windows doesn't support Ruby forks (only spoons. Rimshot!).
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
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 :)
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
精彩评论