开发者

Ant run bat file and go forward

I'm stuck with a stupid problem开发者_JAVA百科. The problem is:

I need to start a proprietary self-made server. This server is started using a .bat file (I'm on the Windows OS).

I've wrote an Ant target:

  1. <exec /> start-stupid-server.bat
  2. <waitfor /> server port.

So the bat file is executed, the server listens for the port. Ant writes BUILD SUCCESSFUL and doesn't quit. Ant waits until the server window is closed. I've tried 100,500 ways to overcome it, but I didn't succeed. Is there a way in Ant to a <exec /> bat file and forget about it?

<exec spawn="true" /> doesn't help, because Ant closes the server window and the server shuts down.

I've tried <exec /> with:

start start-stupid-server.bat,
start /b start-stupid-server.bat

Nothing helps :( Ant still waits until the server window is closed.

Here is my target:

<target name="start_proprietary_server" depends="bootstrap">
    <echo message="going to stop MDM server instance... "/>
    <forget daemon="true">
        <exec executable="${app.custom.root}/bin/stopAll.bat" dir="${app.custom.root}/bin"  />
    </forget>
    <waitfor
            maxwait="20" maxwaitunit="second"
            checkevery="1" checkeveryunit="second" timeoutproperty="mdm.stop.error">
        <and>
            <not> <socket server="localhost" port="12000" /> </not>
            <not> <socket server="localhost" port="14444" /> </not>
        </and>
    </waitfor>

    <if>
        <isset property="mdm.stop.error" />
        <then>
            <echo message="There are some problems while stopping MDM server. See what's went wrong" />
        </then>
        <else>
            <echo message="MDM server successfully stoped." />
        </else>
    </if>

    <echo message="going to start MDM server instance... "/>

    <!--
        Starts but doesn't exit target
        <exec executable="cmd" dir="${app.custom.root}/bin" >
            <arg value="/c start startAll.bat" />
        </exec>
    -->

    <!--
        <forget daemon="true">
            <exec executable="cmd" dir="" >
                <arg value="/c startAll.bat" />
            </exec>
        </forget>
    -->

    <forget daemon="true">
        <exec executable="${app.custom.root}/bin/startAll.bat" dir="${app.custom.root}/bin"  />
    </forget>


    <echo message="Wating for localhost ports #12000 and #14444"/>
    <waitfor
            maxwait="40" maxwaitunit="second"
            checkevery="3" checkeveryunit="second" timeoutproperty="mdm.start.error">
        <and>
            <socket server="localhost" port="12000" />
            <socket server="localhost" port="14444" />
        </and>
    </waitfor>

    <if>
        <isset property="mdm.start.error" />
        <then>
            <echo message="There are some problems while starting MDM server. See what's went wrong" />
        </then>
        <else>
            <echo message="MDM server has been started." />
        </else>
    </if>
</target>

Here is the bat file:

call .\bcmenv.bat
start /min .\startLocator.bat
sleep 5

start /min .\startServices.bat
exit

I've tried to exec it using the forget tag, using start, start /b, and call, but nothing helps. Ant doesn't finish the task until the server window is closed.

If I use spawn without forget, Ant closes the server window when exiting the target. It uses spawn in conjunction with forget, the Ant target is not finished until the server window is closed.

What can I try next?


You can make another batch file which starts the server and returns immediately using start command:

start <path_to_server_bat> <args>

Have you tried spawn=true?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜