我的意思不是 load 或 require 之类的,而是产生新进程(所以我可以使用多个 CPU). 解决方案 Avdi Grimm 写了一系列文章在 Devver 博客上关于去年夏天启动 Ruby 子进程的不同方法:在 Ruby 中启动子进程的十几种(左右)方法:第 1 部分在 Ruby 中启动子进程的十几种(左右)方法:第 2 部分十几种(左右)在 Ruby 中启动子进程的方法:第 3 部分注意子进程中的管道重复[注意:似乎第 4 部分尚未发布.]In ruby, is it possible to specify to call another ruby script using the same ruby interpreter as the original script is being run by?For example, if a.rb runs b.rb a couple of times, is it possible to replacesystem("ruby", "b.rb", "foo", "bar")with something likerun_ruby("b.rb", "foo", "bar")so that if you used ruby1.9.1 a.rb on the original, ruby1.9.1 would be used on b.rb, but if you just used ruby a.rb on the original, ruby would be used on b.rb?I'd prefer not to use shebangs, as I'd like it to be able to run on different computers, some of which don't have /usr/bin/env.Edit: I didn't mean load or require and the like, but spawning new processes (so I can use multiple CPUs). 解决方案 Avdi Grimm wrote a series of articles on the Devver blog about different ways to start Ruby subprocesses last summer:A Dozen (or so) Ways to Start Subprocesses in Ruby: Part 1A Dozen (or so) Ways to Start Subprocesses in Ruby: Part 2A Dozen (or so) Ways to Start Subprocesses in Ruby: Part 3Beware of pipe duplication in subprocesses[Note: it appears that part 4 hasn't been published yet.] 这篇关于从 ruby 脚本运行另一个 ruby 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-24 06:04