2

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"
end

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.

Bogdan Popa
  • 1,099
  • 1
  • 16
  • 37
  • 1
    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\`` – omnikron Sep 20 '16 at 10:55
  • @omnikron thanks mate, worked like a charm :) write it as an answer and I'll accept it. Cheers! – Bogdan Popa Sep 20 '16 at 10:58
  • done! Glad it helped :) – omnikron Sep 20 '16 at 10:59

2 Answers2

2

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`
omnikron
  • 2,211
  • 17
  • 30
1

Perhaps you should use backticks or the %x syntax.

Also see answers to: Ruby, Difference between exec, system and %x() or Backticks

William Price
  • 4,033
  • 1
  • 35
  • 54
mrstebo
  • 911
  • 9
  • 12