I have a problem with adding a path to the environment of a process using processbuider. I have no clue why the process is ignoring the environment. Here is my example:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
public class main {
public static void main(String [ ] args) {
try {
String s = null;
ProcessBuilder pb = new ProcessBuilder("/bin/bash", "-c", "fsl");
Map<String, String> env;
env = pb.environment();
env.put("FSLDIR", "/usr/local/fsl/bin/");
Process p = pb.start();
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
System.out.println("Process p:");
// read the output from the command
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
//////////*********\\\\\\\\\\\
ProcessBuilder pb2 = new ProcessBuilder("/usr/local/fsl/bin/fsl");
s = null;
Process p2 = pb2.start();
stdInput = new BufferedReader(new
InputStreamReader(p2.getInputStream()));
stdError = new BufferedReader(new
InputStreamReader(p2.getErrorStream()));
System.out.println("Process p2:");
// read the output from the command
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Output:
Process p:
/bin/bash: fsl: command not found
Process p2:
DISPLAY is not set. Please set your DISPLAY environment variable!
And you see FSL wants some more variables to be set. That is why p2 is not an option.