1

我有一个构建需要一个任务来启动一个进程,并且需要一个在最后杀死它。

我有一个包含进程 ID 的文件,但无法弄清楚如何让 ant 扩展命令替换以便将该文件的内容传递给 kill 命令。

我努力了:

<target name="kill process">
    <exec executable="kill">
        <arg value="`cat process-file`"/>
    </exec>

...

和:

<target name="kill process">
    <exec executable="kill">
        <arg value="$(cat process-file)"/>
    </exec>

但两者都转换为字符串文字,因此导致: [exec] kill: failed to parse argument: '$(cat process-file)'

有没有办法让蚂蚁扩展这些?或者完全不同的途径来实现这一点?

4

1 回答 1

3

您可以使用 Ant 的loadfile任务将文件的内容读入属性。

<loadfile srcFile="process-file" property="pid">
  <filterchain>
    <striplinebreaks/>
  </filterchain>
</loadfile>
<exec executable="kill">
    <arg value="${pid}"/>
</exec>

编辑:添加过滤器链来处理额外的空白

于 2015-02-08T05:17:57.620 回答