I'm building a restarter for my litte program.
The basic idea is to run a process using Runtime.getRuntime().exec
, that excecutes the program itself, then running System.exit(0);
this is the code that does the restarting:
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
Runtime.getRuntime().exec(strList);
} catch (IOException e) {
e.printStackTrace();
}
}
});
// exit
System.exit(0);
Where strList
is an String[]
that is something like:
{"/bin/bash","-c","java -jar path/to.jar"}
Don't worry about OS portability, the program will be run exclusively on Ubuntu.
The program restarts fine, or at least a new process is running (and continuing to restart itself after a while)
The problem is after restart I loose the console, so i have no idea what is actually happening with the program.
Is there any way to start the new process in "the same window" or any way to access it (maybe by using screen?)?