Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
242 views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...