Windows-在单独的过程中执行Ruby函数

发布于 2025-02-03 09:46:46 字数 613 浏览 5 评论 0原文

我正在尝试在Windows系统上的单独过程中执行Ruby函数。在Mac上,我使用了fork方法。但这在Windows上不起作用。我还尝试了Spawn方法。但这似乎也不起作用。

def test_1
  puts "Hello"
end

def test_2
  puts " World"
end

在Windows上的Mac(Works)上

pid_1 = Fork.do
  test_1
end

pid_2 = Fork.do
  test_2
end

Process.waitall

(不起作用)

pid_1 = Process.spawn(test_1)
pid_2 = Process.spawn(test_2)
Process.waitall

Exception: NoMethodError - undefined method `spawn' for Process:Module

Ruby版本:2.0 有人可以帮助我理解我缺少的东西。

编辑:找到问题。 Ruby版本是旧版本(1.8.7),该版本未实现此方法。

I'm trying to execute Ruby functions in separate processes on my Windows system. On Mac, I used the Fork method. But that doesn't work on Windows. I also tried the spawn method. But that doesn't seem to work either.

def test_1
  puts "Hello"
end

def test_2
  puts " World"
end

On Mac (Works)

pid_1 = Fork.do
  test_1
end

pid_2 = Fork.do
  test_2
end

Process.waitall

On Windows (Doesn't work)

pid_1 = Process.spawn(test_1)
pid_2 = Process.spawn(test_2)
Process.waitall

Exception: NoMethodError - undefined method `spawn' for Process:Module

Ruby version: 2.0
Can someone help me in understanding what I'm missing.

Edit: Found the issue. The Ruby version was old (1.8.7) which doesn't implement this method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文