How to start and monitor an external command line process with java under windows XP
<p>I have a java question about launching and monitoring external processes under Windows XP.</p>

<p>I have written a coommand-line simulation program with C++ and mingw which takes an XML file as input file. I am now writing a pre-processor for that program (I call it "Launcher"). </p>

<p>Launcher allows user to edit parameters and save to an XML file, it also provides ability to start simulation process with an input file and kill the simulation process when it's still running. In order to do this, it must be able to monitor the launched command-line simulation process.</p>

<p>In Launcher, I created a new thread and I used <code>ProcessBuilder</code> or <code>Runtim.getRuntime()</code> method in its <code>run()</code> function to start simulation process. The command used to construct ProcessBuilder to start external simulation program was as follows:</p>

<pre><code>cmd.exe /c start &lt;simulation program&gt; -i &lt;input file&gt;
</code></pre>

<p>The simulation process did start as I expected with above command and a command window appears.However, the thread which contains this Process object ends immediately. Therefore, I couldn't track the process and terminate it from Launcher program.</p>

<p>I modified the command to following:</p>

<pre><code>cmd.exe /c start /wait &lt;simulation program&gt; -i &lt;input file&gt;
</code></pre>

<p>The thread used to start this process didn't end until the command-line window running the simulation process ended.
However, when I tried to interrupt this thread, the thread did end but the external simulation process didn't. Therefore, I still can't kill that process from my java program.</p>

<p>I have studied this problem for two days, most materials I found are focusing on how to start an external process but not focusing on monitoring it after it started. I hope I can find a simple and elegant way to start an external command-line process with Java under XP while I still can monitor and terminate that command-line process through the Java program which starts it.</p>
