0
在以下示例中,用於在Java中調用「php hello.php」的兩種方法有什麼區別? p1 vs p2?在Java中,getRuntime()。exec(php hello.php)和getRuntime()。exec(array)有什麼區別?
String[] commands;
String command = "php hello.php";
commands[0] = "php";
commands[1] = "hello.php";
Process p1 = Runtime.getRuntime().exec(command);
Process p2 = Runtime.getRuntime().exec(commands);
謝謝!
嘿感謝您的幫助!作爲後續,你知道如何在Linux下執行Runtime.getRuntime()。exec(cat someData.json)的功能,但在Windows環境下呢?我目前有Runtime.getRuntime()。exec(「cmd/C type printImagesJson-123.cache」);但readLine()的輸出值是空白的 – user3388884
cat只是將文件寫入stdout,所以我寧願使用java.io.FileReader讀取它。這將是平臺獨立的,你不會產生另一個進程。 –