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读取它。这将是平台独立的,你不会产生另一个进程。 –