java.io.Console console=System.console() returns null in windows
807580Sep 4 2009 — edited Sep 4 2009Hi,
I am trying to capture userid/password on console and using java 6 console api for that.
But it returns null, when I call System.console().
Can anyone please let me know the possible reason Or how can I use console API to capture password on console. The code, what I am using is
public static String getUserInfoFromCommandLine(String caption, boolean isPassword){
String str=null;
Console cons = System.console();
if(cons!=null){
if(isPassword==false){
str = cons.readLine("[%s]", caption);
}else{
char[] passwd = cons.readPassword("[%s]", caption);
str=String.valueOf(passwd);
}
}else{
System.out.println("System Does Not Support Console Operation.");
System.exit(0);
}
return str;
}