Cannot launch ANY process in Java (ProcessBuilder process immediately returns with exit code 128)

牧云@^-^@ 提交于 2019-12-11 03:03:40

问题


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 with 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

回答1:


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.




回答2:


You should call p.waitFor() before p.exitValue().



来源:https://stackoverflow.com/questions/6037336/cannot-launch-any-process-in-java-processbuilder-process-immediately-returns-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!