I must to implement command : java -jar test.jar page.xml | mysql -u user -p base
in ant. So i Have tried with this task:
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>
Explaining why Amilie's answer is the correct solution:
The difference between Amilie's correct solution compared to Brain Agnew's solution is the subtle difference between them. Brian had the second arg as a "value" while Amilie is using "line".
Here's why Amilie's is correct, per Apache Ant Documentation:
"value | a single command-line argument; can contain space characters."
"line | a space-delimited list of command-line arguments."
<exec executable="bash">
<arg value="-c"/>
<arg line='"java -jar test.jar page.xml | mysql -u user -p base"'/>
</exec>
When you run a java program from Ant, the input and out from the program are captured by the Ant runtime - you can't try and redirect them elsewhere using that pipe.
If you want to do that, you might have better luck with the exec
task, although that might suffer from the same problem.
There you are actually running a java command.
You need to use Exec task http://ant.apache.org/manual/Tasks/exec.html but not sure if there also you can run piped commands or not. Give it a try.
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.
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.