Bogdan Popa Bogdan Popa - 1 year ago 82
Ruby Question

Run two ruby scripts from rake task

So this is a simple rake task:

task :map_reduce do
puts 'Running map reduce scripts...'
ruby "#{PADRINO_ROOT}/map_reduce/raw_visits_map.rb '03-08-2016' 90" && ruby "#{PADRINO_ROOT}/map_reduce/raw_visits_reducer.rb"

The first script outputs the result in STDOUT to be further read by the so called 'reducer'.
In the terminal, I am able to run those two scripts like:

ruby first_script.rb param1 param2 | ruby second_script.rb

So the second script can read from STDOUT like

res = ARGF

But how can I line up the 2 executions inside that rake task?

How I wrongfully tried it's not working.

Answer Source

It might be easier to require the ruby class directly into your rake task, but if you want to run a script from a rake task you can run any shell code in Ruby using backticks, like this: ruby first_script.rb param1 param2 | ruby second_script.rb

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download