如何使用參數執行命令?如何在Java中執行帶有參數的命令?我試過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貢獻1951條經驗 獲得超3個贊
Process p = Runtime.getRuntime().exec("php /var/www/script.php -m 2");

繁華開滿天機
TA貢獻1816條經驗 獲得超4個贊
Runtime.getRuntime().exec(new String[]{"php","/var/www/script.php", "-m", "2"});

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