I am running a Java program on Unix (AIX to be specific) and need to call an external shell script. Additionally, I need to set some environment variables that will be available to the shell script (technically, they need to be avaiable to an Ant program that the shell script invokes). I know this setup sounds strange but my Java program is an installation program that wraps a pre-existing Ant script. I want to use it to prompt for some passwords to feed into the Ant script as environment variables as encrypted values.
My problem is that the environment variables I add are not visible to the shell script and, by extension, my Ant script. I am using the ProcessBuilder.enviroment() map to set this as follows:
ProcessBuilder pb = new ProcessBuilder("build.sh", "install");
pb.directory("app_root/install"));
//if we have encrypted passwords, set them as environment variables on the child process
if (this.encryptedPasswords.size() > 0)
{
for (Entry<String,String> entry : this.encryptedPasswords.entrySet())
{
String userName = entry.getKey();
String encryptedPassword = entry.getValue();
if (this.debug == true)
System.out.println("Adding environment variable [" + userName + "] with value [" + encryptedPassword + "]");
pb.environment().put(userName, encryptedPassword);
}
}
My shell script (which I cannot easily change) basically looks like this:
#!/bin/sh
. ./build.env.sh
ant -buildfile build_impl.xml $*
The build.env.sh script sets and export some environment variables like WEBLOGIC_HOME, etc. that are static and also used by the Ant script.
This same concept has worked on Windows. I am sure it is something with Unix/AIX that I am not familiar with. For instance, do I need to be exported these new environment variables? If so, how would that be done from ProcessBuilder in Java?
Thanks in advance.