This question is a followup on Set environment variable in shell script/access in Java program. I am trying to fetch the environment variable in Java after running a shell script but unable to do so
Shell Script: getDetails.sh:
#!/bin/bash
# File: getDetails.sh
export userDetails="USER123"
# echo "User Details for App :$userDetails"
Java method:
String details = new String("source " + "getDetails.sh");
ProcessBuilder processBuilder = new ProcessBuilder("/bin/bash", "-c", details);
Process getPwdProc = processBuilder.start();
System.out.println("Details - " + processBuilder.environment().get("userDetails"));
The java method returns/prints null for the environment variable - userDetails.
P.S. - Please note that the use of InputStream/BufferedReader to read the userDetails is not possible here as echoing the details is not allowed for the program/organization.