【发布时间】:2011-04-14 15:09:53
【问题描述】:
我遇到了一个愚蠢的问题。问题是:
我需要启动一个专有的自制服务器。此服务器是使用 .bat 文件启动的(我使用的是 Windows 操作系统)。
我写了一个Ant 目标:
<exec /> start-stupid-server.bat-
<waitfor />服务器端口。
于是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 标签、start、start /b 和call 执行它,但没有任何帮助。 Ant 在服务器窗口关闭之前不会完成任务。
如果我在没有forget 的情况下使用spawn,Ant 会在退出目标时关闭服务器窗口。它结合使用 spawn 和忘记,直到服务器窗口关闭,Ant 目标才完成。
接下来我可以尝试什么?
【问题讨论】:
-
您能提供更多信息吗?也许查看您的批处理文件会有所帮助。
-
嗨布拉德。我添加了有关该问题的更多信息。我累了:忘记,shellscript,exec,call,start...没有任何帮助。 Ant 在专有的 start_server.bat 关闭之前不会完成目标。
标签: ant asynchronous batch-file exec