Problem in Runtime.exec()

I am trying to launch a new java application from my java program like this-:

import java.io.*;

publicclass test123{

//String userStr="";

publicstaticvoid main(String args[])throws Exception{

Process p = Runtime.getRuntime().exec("java JavaExec",null,currentDir);

Thread.sleep(10000);

System.out.println("After Destroy");

}

}

The JavaExec file抯 code is -:

import java.io.*;

import org.apache.log4j.Logger;

publicclass JavaExec

{

static Logger logger = Logger.getLogger("JavaExec.class");

publicstaticvoid main(String args[])

{

try

{

Runtime runtime = Runtime.getRuntime();

Process process = runtime.exec("notepad");

int exitCode=0;

while(true)

{

//logger.info("Inside the infinite while loop in javaexec");

try

{

exitCode = process.exitValue();

System.out.println(exitCode);

process.destroy();

process = runtime.exec("notepad");

}

catch(IllegalThreadStateException itse)

{

System.out.println("Inside exception");

}

}

}catch (Throwable t)

{

t.printStackTrace();

}

}

}

Notepad opens when I execute the test123 class but instead of remaining open even if I close it , I am able to close notepad. The JavaExec only starts processing again when my main quits.

Please let me know the solution to this problem.....

Thanks in Advance

Inder Jeet Singh

[3074 byte] By [my_java_screena] at [2007-11-26 19:01:36]
# 1
Convoluted at best. You don't need that loop, just useexitCode = process.exitValue();and it will block until notepad exits.P.S. Why a Runtime.exec() executing a Java program that does a Runtime.exec() on notepad?
sabre150a at 2007-7-9 20:46:25 > top of Java-index,Java Essentials,Java Programming...
# 2
A much simpler way (assuming you can live with the other app being in the same JVM) is:JavaExec.main(args_go_here);
Dick_Adamsa at 2007-7-9 20:46:25 > top of Java-index,Java Essentials,Java Programming...