0
我想从java程序执行下面的命令。无法执行来自java的命令
java -jar jarfile.jar -dir C:/MyDirectory -out C:/MyDirectory/example.html
我试过以下,但其开放的命令提示符,但它不执行
Runtime rt = Runtime.getRuntime();
try {
rt.exec(new String[] { "cmd.exe", "/c", "start" , "java -jar exampleJar.jar -dir C:\\MyDirectory -out C:\\MyDirectory\\exampleHtml.html" });
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
您应该考虑使用'ProcessBuilder'(http://stackoverflow.com/questions/10723346/why-should-avoid-using-runtime-exec-in-java) –