1

I have a build that needs a task for starting a process, and one for killing it at the end.

I have a file with the process id in it, but cannot figure out how to make ant expand the command substitution in order to pass the contents of that file to the kill command.

I have tried:

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

...

And:

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

but both are converted to string litterals, and so result in: [exec] kill: failed to parse argument: '$(cat process-file)'

Is there a way to make ant expand these? Or an altogether different route to accomplish this?

Bryan Agee
  • 4,924
  • 3
  • 26
  • 42

1 Answers1

3

You can use Ant's loadfile task to read the file's content into a property.

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

EDIT: added filterchain to deal with additional whitespace

Stefan Bodewig
  • 3,260
  • 15
  • 22
  • This is getting closer, but for some reason the property has a tab in front of it, and a linebreak; that causes kill to fail again with: failed to parse argument: ' 15718 [exec] ' – Bryan Agee Feb 08 '15 at 05:25
  • Ahhh... it seems you must also use filterchain + striplinebreaks to make this work. If you can add those to your answer, then I can select it. – Bryan Agee Feb 08 '15 at 05:29
  • Ah, thanks, didn't think of the pid file containing additional whitespace. – Stefan Bodewig Feb 08 '15 at 07:10