How to execute command with parameters?

前端 未结 3 1496
予麋鹿
予麋鹿 2020-11-22 16:34

How am I to execute a command in Java with parameters?

I\'ve tried

Process p = Runtime.getRuntime().exec(new String[]{\"php\",\"/var/www/script.php -         


        
相关标签:
3条回答
  • 2020-11-22 17:12

    Use ProcessBuilder instead of Runtime#exec().

    ProcessBuilder pb = new ProcessBuilder("php", "/var/www/script.php", "-m 2");
    Process p = pb.start();
    
    0 讨论(0)
  • 2020-11-22 17:15

    The following should work fine.

    Process p = Runtime.getRuntime().exec("php /var/www/script.php -m 2");
    
    0 讨论(0)
  • 2020-11-22 17:16

    See if this works (sorry can't test it right now)

    Runtime.getRuntime().exec(new String[]{"php","/var/www/script.php", "-m", "2"});
    
    0 讨论(0)
提交回复
热议问题