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

