Get input in Rake Tasks

This won’t work:

cvs_username = gets

to get it working you have to ask input from STDIN:

cvs_username = STDIN.gets

And this is a helper method:

def ask message
print message
STDIN.gets.chomp
end
# ...
cvs_username = ask('Please insert your CVS username')

Published in:  on November 7, 2008 at 2:47 pm Comments (2)

The URI to TrackBack this entry is: http://elia.wordpress.com/2008/11/07/get-input-in-rake-tasks/trackback/

RSS feed for comments on this post.

2 Comments Leave a comment.

  1. works like a charm.

  2. nice helper..

    My ‘fork’ lol:

    def ask message, default_response=”
    print “#{message} ”
    response = STDIN.gets.chomp
    response.blank? ? default_response : response
    end


Leave a Comment