在 Java 中執行命令列
在 Java 中,可以使用 Runtime.exec() 方法存取命令列。透過利用此方法,Java 應用程式可以執行原本需要在終端機中手動執行的命令列。
問題:
使用者希望執行以下命令列在Java中應用程式:
java -jar map.jar time.rel test.txt debug
解決方案:
解決方案:import java.lang.Runtime; import java.lang.Process; public class CommandLineRunner { public static void main(String[] args) { Runtime rt = Runtime.getRuntime(); Process pr = rt.exec("java -jar map.jar time.rel test.txt debug"); // Handle the process output or error (if any) here pr.waitFor(); // Wait for the command to finish } }
以上是如何在 Java 中執行命令列?的詳細內容。更多資訊請關注PHP中文網其他相關文章!