I’m writing a script to launch a Java app and securely provide the Java app with a password. The password should not be echoed to the screen and should not be visible to anyone listing running processes. The following script works fine for this:
echo -n "enter password: "
read -r -s password
java -classpath $CLASSPATH com.myclientscompany.Manage<<EOF
$password
EOF
…with the Java program reading the password as a line from stdin.
The problem I’m facing is that after taking the password in this way, I want the Java app to interactively accept further inputs from the user via the console. As it stands currently, every subsequent attempt to read from stdin within Java returns immediately with null.
Is there a way to switch the stdin back to taking console input at the end of this script?
If you are using 1.6 or above, you can use
Console.readPassword()from inside your Java program to enter the password.