David Rivers
David Rivers

Reputation: 2945

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!).

Upvotes: 12

Views: 8596

Answers (3)

David Rivers
David Rivers

Reputation: 2945

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 :)

Upvotes: 6

rogerdpack
rogerdpack

Reputation: 66741

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

Upvotes: 3

Charles Roper
Charles Roper

Reputation: 20625

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

Upvotes: 13

Related Questions