0

I have seen the popular post on how to pass parameters to rake. I copy pasted sample code from that post and it is not working for me:

Rakefile.rb:

require 'rake'

task :my_task, [:arg1, :arg2] do |t, args|
  puts "Args were: #{args}"
end

Then at the command line I run

rake my_task[1,2]

Error

rake aborted! Don't know how to build task 'my_task[1'

It looks like the comma is truncated. It may need to be escaped, but I don't know how. I tried rake my_task[1\,2] and it only added a slash to the error. The answer has over 700 upvotes so...what am I doing wrong?

rake --version : rake, version 10.3.2

I'm using Console2 shell which says "Windows PowerShell" when I launch a new terminal instance.

Community
  • 1
  • 1
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
  • 1
    What shell are you using? Try quoting the argument to Rake: `rake 'my_task[1,2]'`. – Andrew Marshall Feb 22 '15 at 15:39
  • @AndrewMarshall - I tried `cmd` and it works fine. So its definitely my shell. When I switch between the two modes "Console2 and PS" both say "Windows Powershell". And your way worked! If you put this as an answer I will mark it. Thanks! – P.Brian.Mackey Feb 22 '15 at 16:18

1 Answers1

2

Your shell is probably interpreting the argument to Rake as something special, so quote it to avoid that from happening:

rake 'my_task[1,2]'
Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214