84

I get an error whenever I try to use the function gets within a rake task. Is there a way to make it work?

The error says, "no such file or directory - (rake task name)"

James A. Rosen
  • 64,193
  • 61
  • 179
  • 261

2 Answers2

166

The problem is that Kernel#gets (which is what you're calling if you just use gets by itself) assumes you're pulling from a file named by the arguments passed to Rake. That means gets tries to return the content of a file called [rake-task-here], which almost certainly doesn't exist.

Try STDIN.gets.

Kerrick
  • 7,420
  • 8
  • 40
  • 45
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
-4

I don't think that you should be using gets in a rake task, if you need to get input from the command line you probably should pass it in as a parameter, but if you post some code that is not working then I am sure you will get a better answer.

nitecoder
  • 5,496
  • 1
  • 28
  • 35
  • 22
    In general, command line arguments _are_ a better option, but there are plenty of good reasons to use gets within a rake task. Most of them have to do with authentication or verification that you really want to be doing what you tell rake to do. ("deploy production code") – James A. Rosen Feb 23 '09 at 14:55