This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes How to execute a grep command from Ant? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Reply Bookmark "How to execute a grep command from Ant?" Watch "How to execute a grep command from Ant?" New topic
Author

How to execute a grep command from Ant?

Johnson arthur
Greenhorn

Joined: Jul 26, 2012
Posts: 2

Hello,

Can some one please help on how to execute a linux command like grep from ANT ?

Here is the command i want to run (grep = xyz.txt > abc.properties)

Can we use <exec task from ANT ? If so how to use it ?

Can i use something like this ?

<exec dir="${input}" command="grep = xyz.txt > abc.properties"/>

Please suggest!!

Thank you!!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5536

Yes, you want to use the <exec> task. Check out the docs for that task, it will give you some examples on how to invoke apps:
http://ant.apache.org/manual/Tasks/exec.html
Look specifically at the "output" property, that is how you would specify the "abc.properties" in your example.
Look at the <args> nested element, that is how you pass command line option to grep.
Finally, the "executable" property should be set to "grep", not to the full command line.

If you still have problems, feel free to post again, we'll be glad to help.


JBoss In Action
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to execute a grep command from Ant?
 
Similar Threads
Using Unix "grep" command in java...
named character classes in grep
Ant task for user interactive input for shell command execution
multiple greps within on exec statement?
Running UNIX command from Java