tags:

views:

26

answers:

1

How can I mask input from the command line? Basic use case: I want to enter a password when prompted, and I need to either see *'s or nothing at all.

+3  A: 

Since you can call Java libraries from Groovy, you may find your answer in the question How to mask a password in Java 5?.

In short, use Console.readPassword() (Java 6 or later).

Greg Hewgill
I get this when running even Console.readLine(): Caught: groovy.lang.MissingMethodException: No signature of method: static java.io.Console.readLine() is applicable for argument types: () values: []
Zombies
System.console().readLine() according to TFM http://java.sun.com/javase/6/docs/api/java/io/Console.html
tim_yates
Oddly enough this is incredibly frustrating task for a scripting language....
Zombies
System.console() doesn't exist in groovy. Trying to reference anything off of it throws a NPE: Caught: java.lang.NullPointerException: Cannot invoke method readLine() on null object
Zombies
What was making System.console() fail was the faulty eclipse plugin... Works now via shell.
Zombies