I need to start 1-3 external programs in my Java application that have paths defined by the user. I have few requirements:
1) I don't want the program to execute if it is already running
2) I don't want any of the programs to steal focus from my Java application
3) I don't care if any of them fail to start or not...they just need to fail silently.
Here is what I have come up with so far:
ProcessBuilder pb = new ProcessBuilder(userDefinedPath1);
try {
pb.start();
}
catch (Exception e) {
// Something went wrong, just ignore
}
And then I obviously just repeat that 3 more times with the other two paths. This starts like I would expect and meets my third requirement just fine, but fails on the first two.
Can I make this work as I want it to? Thanks in advance.
Edit:
Thanks for the advice so far. Some points of clarification:
1) I don't have any control of these other apps. They are third party. Also, they could have been start or stopped by the user manually at any time.
2) I know the EXACT names of the executables (e.g. "blah.exe") and they will ALWAYS be the same, but the paths to the executables won't necessarily be.
3) Batch file wrappers are not feasible here.
4) The other apps are NOT java apps, just plain old Windows executables.
Does that change anything?
Also, of the two points that I'm trying to solve, the second one is more important. The applications I'm running seem to detect if another one of itself starts and close the duplicate, but it creates a bad user experience (brings up splash screen, flashes on the taskbar, etc). The focus issue is much more important to solve.