I am working on Java web application that should get the decrypted password from .sh file. (e.g file name: decryppwd.sh)
My issue is it returns a blank password when using variable inside the decryppwd.sh file.
E.g:
#decrypted password#
pwd='Welcome123'
echo pwd
#returns: ''
But if we directly use echo to return the password; it is returning the password from decryppwd.sh file.
E.g:
#decrypted password#
echo 'Welcome123'
#returns: Welcome123
My code:
public static String callPwdShellScript(String schema) throws IOException {
String s = null;
Process p =null;
String hostname =null;
String value2 ="oracle";
try {
p = Runtime.getRuntime().exec(“/usr/bin/bash /app/project/config/decryppwd.sh”);
BufferedInputStream buffer = new BufferedInputStream(p.getInputStream());
BufferedReader commandResult = new BufferedReader(new InputStreamReader(buffer));
String line = null;
while((line = commandResult.readLine())!=null)
{
value2 = line;
}
catch(IOException e)
{
e.printStackTrace();
logger.error("callPwdShellScript IOException: " + e.getMessage());
}
catch(Exception e) {
logger.error("callPwdShellScript Exception: " + e.getMessage());
}
return value2;
}
Please let me know where I have gone wrong.
I was able to solve my issue by reading only 1st line of the BufferedReader.