Ant run command with pipes

The pipe (|) can only be used in a shell script. You're passing it as an argument to the java process.

So you need to execute a shell script. You can do this by executing (say) bash -c and passing the above as a shell statement (albeit inline - you could write a separate script file but it seems a bit of an overhead here)

  <exec executable="bash">
    <arg value="-c"/>
    <arg line="java -jar test.jar page.xml | mysql -u user -p base"/>
  </exec>

I don't know if this was ever resolved, but I was having a similar problem which I solved by using the following:

<exec executable="bash">
    <arg value="-c"/>
    <arg line='"java -jar test.jar page.xml | mysql -u user -p base"'/>
</exec>

Just thought I would share.


Another solution would be to wrap the java -jar test.jar page.xml | mysql -u user -p base into a separate script and call it with simple <exec> task.

Tags:

Java

Ant