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) –