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,570 points
81 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,640 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,380 points

edited Nov 6, 2018 by Omkar 10,024 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
83 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,050 points
176 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 in Java by Sirajul
• 35,810 points
57 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,880 points
834 views
+8 votes
11 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
123,780 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 parth295
• 4,640 points
1,462 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,640 points
58 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,640 points
224 views