Spawn a multi-threaded Java program from a Windows command line program, spawner won't end until spa

Posted by Ross Patterson on Stack Overflow See other posts from Stack Overflow or by Ross Patterson
Published on 2010-05-17T16:16:32Z Indexed on 2010/05/17 16:21 UTC
Read the original article Hit count: 456

Filed under:
|
|
|
|

Short version:

How can I prevent a spawned Java process in Windows from blocking the spawning process from ending?

Long version:

I'm trying to spawn a multi-threaded Java program (Selenium RC, not that it should matter) from a program launched from the Windows command line (NAnt's <exec> task, again, not that it should matter). I'm doing it using the Windows "start" command, and the spawned process is started and runs correctly. The spawning process receives control back and finishes (NAnt says "BUILD SUCCEEDED"), but doesn't actually exit to the command line. When the spawned process finally terminates (could be hours later), the command process returns and the command line prompt occurs.

For example:

<target name="start_rc">
    <exec program="cmd" failonerror="false" workingdir="${ross.p5.dir}\Tools\selenium\selenium-server-1.0.1" verbose="true">
        <arg value="/C"/>
        <arg value="start"/>
        <arg value="java"/>
        <arg value="-jar"/>
        <arg path="${ross.p5.dir}\Tools\selenium\selenium-server-1.0.1\selenium-server.jar"/>
        <arg value="-userExtensions"/>
        <arg path="${ross.p5.dir}\Tools\selenium\selenium-server-1.0.1\user-extensions.js"/>
        <arg value="-browserSideLog"/>
        <arg value="-log"/>
        <arg value="${ross.p5.dir}\artifacts\selenium.log"/>
        <arg value="-debug"/>
    </exec>
</target>

Produces:

C

:\Ross>nant start_rc
NAnt 0.86 (Build 0.86.2898.0; beta1; 12/8/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/Ross/ross.build
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: start_rc


start_rc:

     [exec] Starting 'cmd (/C start java -jar C:\p5\Tools\selenium\selenium-server-1.0.1\selenium-server.jar -userExtensions C:\p5\Tools\selenium\selenium-server-1.0.1\user-extensions.js -browserSideLog -log C:\p5\artifacts\selenium.log -debug)' in 'C:\p5\Tools\selenium\selenium-server-1.0.1'

BUILD SUCCEEDED

Total time: 4.1 seconds.

... and then nothing until I close the window where Java is running, then ...

C:\Ross>

Obviously something is preventing the nant process from terminating, but shouldn't the Windows START command prevent that?

© Stack Overflow or respective owner

Related posts about java

Related posts about Windows