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
2010-04-22 20:46:48
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
2010-04-23 14:42:48
System.console().readLine() according to TFM http://java.sun.com/javase/6/docs/api/java/io/Console.html
tim_yates
2010-04-23 14:47:06
Oddly enough this is incredibly frustrating task for a scripting language....
Zombies
2010-04-23 14:55:49
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
2010-04-23 14:57:47
What was making System.console() fail was the faulty eclipse plugin... Works now via shell.
Zombies
2010-04-23 15:17:05