Executing commands with parameters in Java

0 votes

How do I execute commands with parameters in Java??

I have tried using the below commands, but they somehow don't work!

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

and:

String[] options = new String[]{"option1", "option2"};
Runtime.getRuntime().exec("command", options);
Sep 5, 2018 in Java by 93.lynn
• 1,620 points
138 views

1 answer to this question.

0 votes

Try using the below command:

Runtime.getRuntime().exec(new String[]{"php","/var/www/script.php", "-m", "2"});
answered Sep 5, 2018 by geek.erkami
• 2,680 points

Related Questions In Java

+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,420 points

edited Nov 6, 2018 by Omkar 26,703 views
0 votes
1 answer

What are optional parameters in Java

Using three dots: public void move(Object... x) { ...READ MORE

answered Apr 27, 2018 in Java by developer_1
• 3,300 points
159 views
0 votes
1 answer

How to pad an integer with zeros on the left in Java?

Use java.lang.String.format() method. String.format("%05d", number ...READ MORE

answered May 31, 2018 in Java by Daisy
• 8,090 points
732 views
0 votes
2 answers

How can we display an output of float data with 2 decimal places in java? Please help

Use String.format()  if you need the value as ...READ MORE

answered Aug 26, 2019 in Java by Sirajul
• 55,420 points
1,660 views
0 votes
3 answers

Does Java support Default Parameters?

You can try this with method overloading. void ...READ MORE

answered Sep 21, 2018 in Java by Sushmita
• 6,890 points
3,691 views
+11 votes
12 answers

Default parameters of XMS and XMX in JVM

You use these Java command-line parameters to ...READ MORE

answered Nov 13, 2018 in Java by Murali
242,949 views
0 votes
2 answers

Java Security: Illegal key size or default parameters

Starting from Java 9 or 8u151, you ...READ MORE

answered Aug 23, 2018 in Java by Parth
• 4,630 points
3,390 views
0 votes
1 answer
0 votes
1 answer

Join array elements with a separator in Java

Using Java 8, you can easily perform ...READ MORE

answered Aug 16, 2018 in Java by geek.erkami
• 2,680 points
165 views
0 votes
1 answer

Sorting an ArrayList in Java

You can easily do this by simply ...READ MORE

answered May 4, 2018 in Java by geek.erkami
• 2,680 points
400 views