如何使用参数执行命令?如何在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贡献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个赞
ProcessBuilderRuntime#exec().
ProcessBuilder pb = new ProcessBuilder("php", "/var/www/script.php", "-m 2");Process p = pb.start();添加回答
举报
0/150
提交
取消
