I'am writing Java console application which takes input parameters from environment variables (Linux). To set these variables, my application must "source" the shell script. I can "source" the script by using Runtime.exec() or with ProcessBuilder, but I have no idea how to get access to created environment variables.
There is my shell script (set_env.sh):
#!/bin/csh
setenv MY_DB DB_NAME
There is Java code to "source" the script above:
ProcessBuilder pb = new ProcessBuilder("csh", "-c", "'source set_env.sh'");
Process p = null;
try {
p = pb.start();
p.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
How can I get access to created MY_DB variable or is there any other solution of my problem?
Any help will be very appreciated. Thank you in advance.
Ok guys. Thanks to your answers. There is my temporary solution. I've written another script that makes "source" and echoes created variables. In the Java code I'am executing it, reading process's inputstream and parse them then.