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,550 points
66 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,320 points

Related Questions In Java

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,220 points
38 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,020 points
43 views
0 votes
1 answer

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

You can use the printf method, for ...READ MORE

answered Jun 4, 2018 in Java by Daisy
• 8,020 points
23 views
0 votes
2 answers

How to left pad a string with zero in java?

String paddedString = org.apache.commons.lang.StringUtils.leftPad("129018", 10, "0") the second ...READ MORE

answered Aug 31, 2018 in Java by Sushmita
• 6,820 points
147 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,820 points
85 views
+6 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
34,368 views
0 votes
1 answer

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,590 points
535 views
+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,360 points

edited Nov 6, 2018 by Omkar 4,446 views
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,320 points
33 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,320 points
137 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.