Can't execute javac or other command line applications in Java using ProcessBuilder under Windows 7

前端 未结 3 1173
梦毁少年i
梦毁少年i 2021-01-29 02:33

I\'m trying to execute javac from Java using ProcessBuilder but i get no output and nothing happens. I tried reading the input stream (as there is a bug where the process hangs

3条回答
  •  误落风尘
    2021-01-29 02:52

    You're using the wrong method of process builder. Use the single string version, i.e. don't pass a string array, just pass a string. The string array version is for when you've already already divided up the command into the program, its options, and its the arguments. As it stands now, its looking for a program executable file called C:\\Windows\\System32\\cmd.exe /c C:\\\"Program Files\"\\Java\\jdk1.6.0_23\\bin\\javac.exe.

    Alternatively, split your command into the program and arguments in the string array and then you can use the String array version of process builder.

    String[] = new String[] {
        "C:\\Windows\\System32\\cmd.exe",
        "/c",
        "C:\\\"Program Files\"\\Java\\jdk1.6.0_23\\bin\\javac.exe"
    }
    

    And

提交回复
热议问题