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?
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?
You can use this:
/* build up command and launch */
String command = "DO SOMETHING";
try {
Runtime.getRuntime().exec(command);
} catch (Exception ex) {
ex.printStackTrace();
}
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.