Unable to use java/groovy console while debugging
I have a very simple groovy script that reads a username and password from the console. If I run the script from the command line it works perfectly. However, if I try to run it from within Intellij, the console is null.
How can I read console input while debugging my script?
String username
String password
def console = System.console()
if (console) {
username = console.readLine('> Please enter your username: ')
password = new String(console.readPassword('> Please enter your password: '))
println "username: ${username} password: ${password}"
} else {
println "Cannot get console, exiting..."
System.exit(1)
}
Please sign in to leave a comment.
Try to avoid using System.console or launch from the command line and attach to the process using remote debug. Please check this thread for some solutions http://stackoverflow.com/questions/4203646/system-console-returns-null . See corresponding issue in our tracker http://youtrack.jetbrains.com/issue/IDEABKL-5949 .