从 ruby​​ 脚本运行另一个 ruby​​ 脚本 [英] Running another ruby script from a ruby script

查看:52
本文介绍了从 ruby​​ 脚本运行另一个 ruby​​ 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ruby​​ 中,是否可以指定使用与运行原始脚本相同的 ruby​​ 解释器来调用另一个 ruby​​ 脚本?

例如,如果a.rb运行b.rb几次,是否可以替换

system("ruby", "b.rb", "foo", "bar")

类似的东西

run_ruby("b.rb", "foo", "bar")

所以如果你在原始文件上使用 ruby1.9.1 a.rbruby1.9.1 将用于 b.rb,但如果你只使用 ruby a.rb 在原版上,ruby 会用在 b.rb 上吗?

我不想使用shebangs,因为我希望它能够在不同的计算机上运行,​​其中一些没有/usr/bin/env.

我的意思不是 loadrequire 之类的,而是产生新进程(所以我可以使用多个 CPU).

解决方案

Avdi Grimm 写了一系列文章在 Devver 博客上关于去年夏天启动 Ruby 子进程的不同方法:

[注意:似乎第 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 replace

system("ruby", "b.rb", "foo", "bar")

with something like

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

[Note: it appears that part 4 hasn't been published yet.]

这篇关于从 ruby​​ 脚本运行另一个 ruby​​ 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆