fguillen
fguillen

Reputation: 38772

How can I execute a shell command in my rvm enviroment?

I'm trying to execute shell commands from Ruby, but in order to these commands to work properly a RVM environment has to be selected. I don't find the way to do so.

For example I'm trying:

require "rubygems"
require "rvm"

RVM.gemset_use! "ruby-1.9.3-p286@my_project"
%x[rails s]

But looks like the rvm environment is not been loaded because the gems are not found.

Update

The only way I'm seeing is

%x[source /Users/fguillen/.rvm/environments/ruby-1.9.3-p286@my_project && rails s]` 

Is this the best way to do this?

Upvotes: 1

Views: 165

Answers (1)

jbr
jbr

Reputation: 6258

I think that rvm-with is just what you are looking for. It would allow you to do:

require "rvm/with"
RVM.with "1.9.3-o286@my_project" do |r|
  puts r.execute "rails s"
end

Upvotes: 2

Related Questions