Ant运行bat文件并继续前进

时间:2011-04-14 15:09:53

标签: ant asynchronous batch-file exec

我遇到了一个愚蠢的问题。问题是:

我需要启动专有的自制服务器。此服务器使用.bat文件启动(我在Windows操作系统上)。

我写了一个Ant目标:

  1. <exec /> start-stupid-server.bat
  2. <waitfor />服务器端口。
  3. 因此执行bat文件,服务器侦听端口。 Ant写出BUILD SUCCESSFUL并且没有退出。 Ant等待服务器窗口关闭。 我已经尝试了100,500种方法来克服它,但我没有成功。 在Ant中有一种方法可以将<exec /> bat文件忘掉吗?

    <exec spawn="true" />没有帮助,因为Ant关闭服务器窗口并且服务器关闭。

    我已尝试使用<exec />

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

    没有任何帮助:( Ant仍然等待服务器窗口关闭。

    这是我的目标:

    <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>
    

    这是bat文件:

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

    我尝试使用forget标记执行此操作,使用startstart /bcall,但没有任何帮助。在服务器窗口关闭之前,Ant无法完成任务。

    如果我使用没有forget的spawn,Ant会在退出目标时关闭服务器窗口。它将spawn与forget结合使用,在服务器窗口关闭之前,Ant目标不会完成。

    我接下来可以尝试什么?

1 个答案:

答案 0 :(得分:0)

您可以创建另一个启动服务器的批处理文件,并使用start命令立即返回:

start <path_to_server_bat> <args>

您是否尝试过spawn=true

相关问题