Cannot launch ANY process in Java (ProcessBuilder process immediately returns with exit code 128)
I am trying to have Java execute another program, and it kept immediately erroring out with exit code 128 and nothing sent to stdout or stderr. I tried a simple "java -version" still wit开发者_开发百科h no luck. When I run it in a cmd window, it runs fine and this code works on similarly configured other machines (Windows Server 2003 x64, Java 1.6 update 25)
When run on command line:
C:\Documents and Settings\zugwalt>java -version
Output:
java version "1.6.0_25" Java(TM) SE
Runtime Environment (build1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)
Then I try this code:
try {
List<String> cmd = new LinkedList<String>();
cmd.add("java");
cmd.add("-version");
ProcessBuilder apb = new ProcessBuilder(cmd);
apb.redirectErrorStream(true);
System.out.println("STARTING w00t!");
Process p = apb.start();
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = input.readLine()) != null) {
System.out.println("OUTPUT: "+line);
}
System.out.println("EXIT: "+p.exitValue());
System.out.println("WAIT FOR: "+p.waitFor());
} catch (Exception ex) {
System.out.println("CAUGHT: "+ex.getMessage());
ex.printStackTrace();
}
Output is:
STARTING w00t!
EXIT: 128
WAIT FOR: 128
So we "solved" this by killing a large number of the system processes. We think the problem is closely related to the issues described here: http://www.arcanadev.com/support/kb/K00000329.aspx, with the process trying to call java's exec being out of available heap space or memory. Very strange.
You should call p.waitFor()
before p.exitValue()
.
精彩评论