title: How do I launch a completely independent process from a Java program?
body: <p>I am working on a program written in Java which, <em>for some actions</em>, launches external programs using user-configured command lines.  Currently it uses <code>Runtime.exec()</code> and does not retain the <code>Process</code> reference (the launched programs are either a text editor or archive utility, so no need for the system in/out/err streams).</p>
  
  <p>There is a minor problem with this though, in that when the Java program exits, it doesn't really quit until all the launched programs are exited.  </p>
  
  <p>I would greatly prefer it if the launched programs were completely independent of the JVM which launched them.</p>
  
  <p>The target operating system is multiple, with Windows, Linux and Mac being the minimum, but any GUI system with a JVM is really what is desired (hence the user configurability of the actual command lines).</p>
  
  <p>Does anyone know how to make the launched program execute completely independently of the JVM?</p>
  
  <hr>
  
  <p><strong>Edit in response to a comment</strong></p>
  
  <p>The launch code is as follows.  The code may launch an editor positioned at a specific line and column, or it may launch an archive viewer.  Quoted values in the configured command line are treated as ECMA-262 encoded, and are decoded and the quotes stripped to form the desired exec parameter.</p>
  
  <p>The launch occurs on the EDT.</p>
  
  <pre><code>static Throwable launch(String cmd, File fil, int lin, int col) throws Throwable {
      String frs[][]={
          { "$FILE$"  ,fil.getAbsolutePath().replace('\\','/') },
          { "$LINE$"  ,(lin&gt;0 ? Integer.toString(lin) : "") },
          { "$COLUMN$",(col&gt;0 ? Integer.toString(col) : "") },
          };
      String[] arr; // array of parsed tokens (exec(cmd) does not handle quoted values)
  
      cmd=TextUtil.replace(cmd,frs,true,"$$","$");
      arr=(String[])ArrayUtil.removeNulls(TextUtil.stringComponents(cmd,' ',-1,true,true,true));
      for(int xa=0; xa&lt;arr.length; xa++) {
          if(TextUtil.isQuoted(arr[xa],true)) {
              arr[xa]=TextDecode.ecma262(TextUtil.stripQuotes(arr[xa]));
              }
          }
      log.println("Launching: "+cmd);
      Runtime.getRuntime().exec(arr);
      return null;
      }
  </code></pre>
  
  <hr>
  
  <p>This appears to be happening only when the program is launched from my IDE.  I am closing this question since the problem exists only in my development environment; <strong>it is not a problem in production</strong>.  From the test program in one of the answers, and further testing I have conducted I am satisfied that it is not a problem that will be seen by any user of the program on any platform.</p>