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?

Community
  • 1
  • 1
minhaz
  • 483
  • 1
  • 5
  • 12

3 Answers3

2

You can use this:

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

try {
    Runtime.getRuntime().exec(command);
} catch (Exception ex) {
    ex.printStackTrace();
}
Baz
  • 35,635
  • 11
  • 69
  • 91
1

You can use Runtime.exec() method.

18bytes
  • 5,751
  • 7
  • 41
  • 67
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.

Arpssss
  • 3,760
  • 5
  • 35
  • 77