I have a java program which executes a shell script. The shell script involves many environment variables in it($HOME). When executing the command from shell, it is working fine. An echo $HOME is giving me the actual path to the command. (The script changes paths and executes commands from changed paths)
$cat nightly.sh
#!/bin/bash
...
echo $HOME
...
echo "end of script"
I see /home/ when executed from the shell at appropriate place.
Now I invoke the same shell script from java program by,
static Proces p;
...
Runtime instance = Runtime.getRuntime();
p = instance.exec(nightly.sh + " " + branch + " " + stack + " " + profile, null, new File(/home/bmanoj/fps/workspaces/APRIL14REL1/testing/integration-tests/regressions));
Now I am capturing the output from the shell to a external file. When I go see the file "echo $HOME" is resulting to a empty line. For that matter I am constructing many relative paths based on the $HOME variable. So nothing in the script works for me now.
Why is it like that? Why isn't the instance invoked by java program not picking up the environment variables? To exactly mock the script as it executes on the shell from the java program what has to be done?