Linux through Java code

Hi

How can I write a Java program to execute Linux commands? What is the best approach:

  • Invoking the Linux shell within Java and executing commands
  • or, using the Java APIs to do the stuff. Since it is platform independent, it'll know itself what to do. We need not check which OS the Java code is executing on. Simply execute the command

It seems like the Runtime Class allows you to fork and exec off a child. Runtime (Java Platform SE 6) A shell is needed to do complicated command lines and to push things to the background, but not for single command runs.