Start program if not already running in Java
<p>I need to start 1-3 external programs in my Java application that have paths defined by the user.  I have few requirements:</p>

<p>1) I don't want the program to execute if it is already running</p>

<p>2) I don't want any of the programs to steal focus from my Java application</p>

<p>3) I don't care if any of them fail to start or not...they just need to fail silently.</p>

<p>Here is what I have come up with so far:</p>

<pre><code>ProcessBuilder pb = new ProcessBuilder(userDefinedPath1);
try {
    pb.start();
}
catch (Exception e) {
    // Something went wrong, just ignore
}
</code></pre>

<p>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.</p>

<p>Can I make this work as I want it to?  Thanks in advance.</p>

<p>Edit:</p>

<p>Thanks for the advice so far.  Some points of clarification:</p>

<p>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.</p>

<p>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.</p>

<p>3) Batch file wrappers are not feasible here.</p>

<p>4) The other apps are NOT java apps, just plain old Windows executables.</p>

<p>Does that change anything?</p>

<p>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.</p>
