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.
Asked
Active
Viewed 6,280 times
1 Answers
13
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).

Community
- 1
- 1

Greg Hewgill
- 951,095
- 183
- 1,149
- 1,285
-
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 Apr 23 '10 at 14:42
-
1System.console().readLine() according to TFM http://java.sun.com/javase/6/docs/api/java/io/Console.html – tim_yates Apr 23 '10 at 14:47
-
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 Apr 23 '10 at 14:57
-
What was making System.console() fail was the faulty eclipse plugin... Works now via shell. – Zombies Apr 23 '10 at 15:17