Hey guys.
I am writing a program that is supposed to help manage an online server. Essentially, the program that runs constantly to handle connections is written in C or something like that and goes through the DOS Box (or similar medium) to display output. Unfortunately, it has some sort of bug where nobody can log on if certain “crash” conditions happen. Normally, I could scan the output of the program to see if an error has popped up, but it doesn’t seem to know there has been one. As such, it needs to be manually restarted.
That’s where my program comes in. It essentially has a timer that checks every hour if there are any users connected to the server (using SQL queries). If nobody is, then it forcibly restarts the server process. I know how to launch the process from within my program, but I have no idea how to quit it first, which is necessary for a restart.
One idea I had was that maybe I could have my program start the program in the first place, then save a pointer to the Runtime.
if (System.getProperty("os.name").contains("Windows"))
{
String[] args = {"rundll32","SHELL32.DLL,ShellExec_RunDLL",locations[1]};
Runtime.getRuntime().exec(args,null,new File(locations[0]));
}
else if (System.getProperty("os.name").equals("Mac OS X"))
{
String[] args = {"open",locations[1]};
Runtime.getRuntime().exec(args,null,new File(locations[0]));
}
Essentially I would just say Process p = Runtime.getRuntime().exec(args,null,new File(locations[0])); Then I can use Java to quit the Process object.
Would this approach work? Also, I would rather do it so the program just has absolute control and doesn’t need to keep track of the Process, so if there is a way to do it like that I would rather.
Thanks.