如何使用參數執(zhí)行命令?如何在Java中執(zhí)行帶有參數的命令?我試過Process p = Runtime.getRuntime().exec(new String[]{"php","/var/www/script.php -m 2"});這不管用。String[] options = new String[]{"option1", "option2"};Runtime.getRuntime().exec("command", options);這也不起作用,因為m參數未指定。
3 回答

蕭十郎
TA貢獻1815條經驗 獲得超13個贊
Process p = Runtime.getRuntime().exec("php /var/www/script.php -m 2");

慕虎7371278
TA貢獻1802條經驗 獲得超4個贊
Runtime.getRuntime().exec(new String[]{"php","/var/www/script.php", "-m", "2"});

溫溫醬
TA貢獻1752條經驗 獲得超4個贊
ProcessBuilder
Runtime#exec()
.
ProcessBuilder pb = new ProcessBuilder("php", "/var/www/script.php", "-m 2");Process p = pb.start();
添加回答
舉報
0/150
提交
取消