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,600 points
3,125 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
4 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,450 points

edited Nov 7, 2018 by Omkar 81,222 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,350 points
946 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,140 points
2,268 views
0 votes
4 answers

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

You can use DecimalFormat. One way to use ...READ MORE

answered Dec 16, 2020 in Java by Gitika
• 65,770 points
164,473 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,920 points
6,937 views
+11 votes
13 answers

Default parameters of XMS and XMX in JVM

Run this code to see all the ...READ MORE

answered Nov 13, 2018 in Java by anonymous
402,641 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,640 points
8,623 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
2,787 views
0 votes
1 answer

Sorting an ArrayList in Java

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

answered May 5, 2018 in Java by geek.erkami
• 2,680 points
2,179 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP