如何使用参数执行命令?如何在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
提交
取消