1

I'm trying to laumch some bat file on my computer, I'm using the Process.exec to do it. The problem is that the bat file start another process, and my program is waiting for it to complete, but I need my program to stop although the child process is keep running. Here is an example of what I'm trying to do, in this code I'm lauching the notepad and the program is stuck until I'm manualy close the notepd window - so what I'm should do for my program to end and notepad will keep running?

    public static Process test3 () throws IOException
   {
   Process p;
   try
      {
      p = Runtime.getRuntime().exec( "notepad" );
      }
   catch ( IOException e )
      {
      return null;
      }
      try
         {
         p.waitFor();
         }
      catch ( InterruptedException e )
         {
         Thread.currentThread().interrupt();
         }


   p.getInputStream().close();
   p.getOutputStream().close();
   p.getErrorStream().close();

   return p;
   } 
kobi
  • 11
  • 1
  • http://stackoverflow.com/questions/931536/how-do-i-launch-a-completely-independent-process-from-a-java-program – Mikhail Jan 15 '12 at 06:59

3 Answers3

0

I suggest you look at the ProcessBuilder class for more flexibility!!!

frewper
  • 1,309
  • 6
  • 17
  • 41
0

If you're running in Windows, try this:

Runtime.getRuntime().exec( "cmd /c start notepad" );
Ted Hopp
  • 222,293
  • 47
  • 371
  • 489
0

Might be this will help :

public class ExternalProcess
{
    public static void main(String... args) throws Exception
    {
        Process p = Runtime.getRuntime().exec("Notepad");
        p.getInputStream().close();
        p.getOutputStream().close();
        p.getErrorStream().close();
        System.exit(0);
    }
}

Simply use System.exit(0);

Regards

nIcE cOw
  • 23,893
  • 7
  • 41
  • 127