Reputation: 5165
I am using the Runtime class to execute a piece of installation of a software. However, its not working, meaning that, after I fire the job (which is created using the Runtime class), after sometime (which is very soon) the installation job just exits. I think the problem is that the main thread must be finishing up and thus killing the Process that is created using the Runtime class. Am I correct ? And what is the solution here ?
this is how I fire my job inside teh main class :
try
{
Runtime.getRuntime().exec(cmd);
}
catch(IOException e)
{
//add logging functionality
e.printStackTrace();
}
Soon after this command, the main function finishes.
There is no problem with the Runtime command. It works .. I can even see it starting(the installation taht I am firing thru the code) and then it suddenly exits.
Upvotes: 4
Views: 180
Reputation: 425033
The process created is a child process for the main thread. If the main thread finishes, the process will be killed, similar to if you executed a command manually and pressed ctrlc or closed the window.
Upvotes: 1
Reputation: 1515
You might want to check out the java.lang.Process class. You probably want something like this:
Process process = Runtime.getRuntime().exec(cmd);
process.waitFor();
The subprocess may be receiving a SIGHUP and exiting.
EDIT:
In context, something like this, I would think:
try
{
Process process = Runtime.getRuntime().exec(cmd);
process.waitFor();
}
catch(IOException e)
{
//add logging functionality
e.printStackTrace();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
Upvotes: 5
Reputation:
This is just a wild guess, but I think to program quit's because you have a error in your code(logical) maybe a while loop that exits to soon,
try to look good at the code that the Runtime executes.
The process is probably in a deadlock. The solution is in the comments, with a sample.
Upvotes: 0