在 Windows 上的 Ruby 中生成后台进程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3840525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spawn a background process in Ruby on Windows?
提问by David Rivers
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!).
我基本上问了与Spawn a background process in Ruby相同的问题,除了我需要在 Windows 环境中生成后台进程!不幸的是,我的研究表明 Windows 不支持 Ruby fork(仅勺子。Rimshot!)。
回答by Charles Roper
The win32-process library, part of the Win32Utils suite, is probably what you're after.
win32-process 库是 Win32Utils 套件的一部分,可能正是您所追求的。
http://win32utils.rubyforge.org/
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
win32-process 库为 MS Windows 添加了 Process.create 和 Process.fork 方法。此外,它还提供了wait、wait2、waitpid 和waitpid2 方法的不同实现。Process.create 方法允许您使用各种不同的配置选项创建本机 MS Windows 进程。
Process.fork 实现应该被认为是实验性的,而不是在生产代码中使用。
安装: gem install win32-process
回答by David Rivers
Charles's answer is great. I also discovered that I can utilize Windows's start
, for example to execute the dir
command as such:
查尔斯的回答很棒。我还发现我可以利用 Windows 的start
,例如执行dir
命令:
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 :)
这会随着进程生成一个 cmd 窗口,这在某些情况下是不可取的。但是,如果这是可以容忍的,那么您就不需要 win32-process 依赖项 :)
回答by rogerdpack
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
1.9.x 的 Process.spawn 似乎运行良好,请参阅http://en.wikibooks.org/wiki/Ruby_Programming/Running_Multiple_Processes的最后一部分