diff --git a/presto-cli/src/main/java/io/prestosql/cli/Console.java b/presto-cli/src/main/java/io/prestosql/cli/Console.java index 2088a0e61e70c..c591a47df7a31 100644 --- a/presto-cli/src/main/java/io/prestosql/cli/Console.java +++ b/presto-cli/src/main/java/io/prestosql/cli/Console.java @@ -26,6 +26,7 @@ import io.prestosql.client.ClientSelectedRole; import io.prestosql.client.ClientSession; import io.prestosql.sql.parser.StatementSplitter; +import jline.console.ConsoleReader; import jline.console.history.FileHistory; import jline.console.history.History; import jline.console.history.MemoryHistory; @@ -169,14 +170,20 @@ private String getPassword() } java.io.Console console = System.console(); - if (console == null) { - throw new RuntimeException("No console from which to read password"); + if (console != null) { + char[] password = console.readPassword("Password: "); + if (password != null) { + return new String(password); + } + return ""; + } + try { + ConsoleReader consoleReader = new ConsoleReader(System.in, System.err); + return consoleReader.readLine("Password: ", (char) 0); } - char[] password = console.readPassword("Password: "); - if (password != null) { - return new String(password); + catch (IOException exception) { + throw new UncheckedIOException("Failed to read password from console", exception); } - return ""; } private static void runConsole(QueryRunner queryRunner, AtomicBoolean exiting)