From: Rob Lucas Date: 2007-11-29T00:25:07+09:00 Subject: Re: Equivalent for unix "read" command in rake tasks? Great. Thanks for the help- I now have something working. Part of what confused me here was that I could write a very simple script like: puts "Input something: " first_input = gets.chomp puts "Input something else: " second_input = gets.chomp puts "You entered: " + first_input + " and " + second_input ... and this would automatically default to looking for input from the user at the command line. However, doing the same thing in a Rakefile, it was by default looking for input from an object with the name of the rake task instead, and I would thus get an error message like: No such file or directory - rake_task_name I thus had to overtly specify to do a "gets" on the standard input: $stdin.gets ... and this worked fine. Perhaps this is obvious to more experienced ruby programmers, but not to me! Thanks again, Rob. Jano Svitok wrote: > On Nov 28, 2007 11:44 AM, Rob Lucas wrote: >> Hi, >> >> Perhaps I'm missing something, but I can't find information anywhere >> about adding any level of interaction with the user into rake tasks. >> What I want really is something equivalent to the unix/ linux command >> "read" so that the task can vary conditionally depending on responses >> from the user. The point would be to replace various shell scripts that >> I have with a single, more elegant Rakefile. > > File.read ? Kernel#gets ? Readline ? > > Rakefile is a normal ruby file, so you can do anything you can do in > ruby. > > You can event call IRB to get more interactivity, although I'm not sure > if that's the intent of rake ;-) > > Other than that, you can parametrize rake tasks through environment > variables: > > either by really setting the env, or passing on command line: > > rake task_name var1=abcd var2=efgh > > then in your rakefile you can reference them as ENV['var1'] and > ENV['var2'] > > J. -- Posted via http://www.ruby-forum.com/.