jmasterx jmasterx - 1 year ago 107
Java Question

Starting a process in Java?

Is there a way to start a process in Java? in .Net this is done with for example:


Is there an equivalent in Java so I can then let the user find the application and then it would work for any OS?

Answer Source

public class CmdExec {

  public static void main(String args[]) {
    try {
      String line;
      Process p = Runtime.getRuntime().exec
        (System.getenv("windir") +"\\system32\\"+" /A");
      BufferedReader input =
        new BufferedReader
          (new InputStreamReader(p.getInputStream()));
      while ((line = input.readLine()) != null) {
    catch (Exception err) {

You can get the local path using System properties or a similar approach.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download