与管道蚂蚁运行命令 [英] Ant run command with pipes
问题描述
我一定要执行命令: Java的罐子Test.jar的page.xml | MySQL的用户-u -p基地
蚂蚁。所以,我试图完成这个任务:
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:
<java jar="test.jar" fork="true">
<arg line="page.xml | mysql -u user -p base"/>
</java>
不过我有带管例外 - |
But i have got en exception with pipe - "|" :
java.lang.IllegalArgumentException: Input already set; can't set to |
所以,这就是问题所在:)
So, that's the problem:)
推荐答案
管道(|)只能在shell脚本中使用。你把它当作参数传递给Java进程。
The pipe (|) can only be used in a shell script. You're passing it as an argument to the java process.
所以,你需要执行一个shell脚本。你可以通过执行这样做(说)的bash -c
,并通过上面的作为外壳的语句(虽然的内联的 - 你可以写一个单独的脚本文件,但它似乎有点这里的开销)
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 value="java -jar test.jar page.xml | mysql -u user -p base"/>
</exec>
这篇关于与管道蚂蚁运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!