如何在 rake 任务中使用“ gets”?

每当我尝试使用 rake 任务中的 get 函数时,都会出错。有办法解决吗?

错误说,“没有这样的文件或目录-(rake 任务名称)”

8010 次浏览

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.

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.