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 -m 2"});
which doesn't work.
String[] options = new String[]{"option1", "option2"}; Runtime.getRuntime().exec("command", options);
This doesn't work as well, because the m
parameter is not specified.
Arguments can be passed to the script when it is executed, by writing them as a space-delimited list following the script file name. Inside the script, the $1 variable references the first argument in the command line, $2 the second argument and so forth. The variable $0 references to the current script.
Parameters can be entered in any order. If a parameter has an associated argument, the argument must always follow the parameter. A parameter must start with a '-'; otherwise, it is assumed to be an argument. The maximum length of any single parameter that can be entered into the CLI is 128 bytes.
See if this works (sorry can't test it right now)
Runtime.getRuntime().exec(new String[]{"php","/var/www/script.php", "-m", "2"});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With