[英]How do I use “gets” on a rake task?
I get an error whenever I try to use the function gets within a rake task. 每当我尝试使用rake任务中的函数时,都会出现错误。 Is there a way to make it work? 有办法使它起作用吗?
The error says, "no such file or directory - (rake task name)" 该错误显示“没有这样的文件或目录-(耙任务名称)”
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. 问题在于, Kernel#gets
(如果您仅使用gets
本身,这就是您要调用的东西)假定您是从传递给Rake的参数命名的文件中提取的。 That means gets
tries to return the content of a file called [rake-task-here], which almost certainly doesn't exist. 这意味着gets
尝试返回名为[rake-task-here]的文件的内容,该文件几乎肯定不存在。
Try STDIN.gets
. 尝试STDIN.gets
。
我不认为您应该在rake任务中使用gets,如果您需要从命令行获取输入,则可能应该将其作为参数传递,但是如果您发布了一些无效的代码,那么我相信您会得到更好的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.