Christoffer Reijer
Christoffer Reijer

Reputation: 1995

Run ruby script from rake task

I have a small ruby script which runs just fine when I run it manually from the command line. It uses three gems which I have installed using "gem install X" and at the top of the script file I have the lines "require X". All works fine.

Now I am creating a task in Rake which will call my ruby script. I have tried to both use

system("/tools/myscript.rb #{foo} #{bar}")

and

`/tools/myscript.rb #{foo} #{bar}`

but both give me this error:

myscript.rb:2:in `require': no such file to load -- ruby-audio (LoadError)

It seems that the gem is not properly loaded. I tried to add the gems to the Gemfile of my Rails app but after all necessary gems had been added and I ran bundle update it ended in error with the mysql adapter not working from my script.

But since the script works just fine from the command line, I thought there really should be an easy way to call it from within the Rake task.

Any ideas?

Upvotes: 0

Views: 3620

Answers (1)

toch
toch

Reputation: 3945

Use

bundle exec <script>

To be sure to load the bundled Gems for the script you want to run

Upvotes: 3

Related Questions