1

Possible Duplicate:
Linux commands from Java

I am developing a Java application where I need to run a linux command from my application. How to do this?

1
  • Yes, but the complaints of the accepted answer there don't necessarily apply to this question. Commented Jun 30, 2012 at 15:08

3 Answers 3

2

You can use this:

/* build up command and launch */
String command = "DO SOMETHING";

try {
    Runtime.getRuntime().exec(command);
} catch (Exception ex) {
    ex.printStackTrace();
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can use Runtime.exec() method.

Comments

1

Example of such:

String [] arrs = new String [3] ;
arrs[0] = "/bin/bash";
arrs[1] = "-c";
arrs[2] = "rm s*"  ;
pp=Runtime.getRuntime().exec(arrs);
pp.waitFor();

Which removes files starting with s from the directory where the java code is stored.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.