I have an issue that is similar to what is found here but the behavior seems to be a bit different on Windows 10: Setting the environment for ProcessBuilder
I want to set up the Path
environment variable in a ProcessBuilder
environment to send to a cmd /C
call.
Consider:
if(platform.startsWith("Windows"))
{
cmd = "cmd";
command = new String[] {"/C", "prog.exe"};
}
String[] args = new String[]();
args.add(cmd);
args.add(command[0]);
args.add(command[1]);
ProcessBuilder pb = new ProcessBuilder(args);
Map<String, String> env = pb.environment();
// set environmental variables for libraries
if(platform.startsWith("Windows"))
{
env.put("Path", env.get("Path") + ";" + "C:\\test");
}
Process process = pb.start();
Using Path
is what is advised in the previous SO post, and that continues to work on Windows 7, but moving to Windows 10, it no longer finds prog.exe
. What I dont understand is that if I change env.put("Path"...
to env.put("PATH"...
it now correctly finds prog.exe
. Has environment variables changed in Windows 10? Im also under the impression that Windows environment variables are case insensitive, but if I set both PATH
and Path
I see each distinctly listed in the environment for Windows 7 and 10.