I think I have found kind of a solution. Not perfect but better than nothing. To get the full environment left after batch execution I used different approach for fireing it up.
Simply I have started the batch in cmd which allowed me to pass additional commands as arguments. Next I had to read the output from the output stream. To my supprise I was also able to get the proper exit code from the batch - note though I had to use the clause:
exit /B <exitCode>
This are mods to the code above:
pb = new ProcessBuilder("cmd.exe", "/c", command, "&&set", "&&exit");
process = pb.start();
pb.redirectErrorStream(true);
process.waitFor();
exitCode = process.exitValue();
stdout = process.getInputStream ();
stdOutReader = new BufferedReader (new InputStreamReader(stdout));
...
String outLine;
while ((outLine = stdOutReader.readLine ()) != null) {
if(outLine.trim().length() > 0){
System.out.println ("OUT STREAM: " + outLine);
}
}
Any comments and alternate solutions are most welcome.