You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Steve Dews <st...@hotmail.com> on 2000/12/21 18:15:03 UTC

unix redirection - how do you specify input files?

Hello,

    Here's what I'm trying to do:

           $ sed -e 's/bad/good/' < oldfile > newfile

    Here's what I've got in Ant:

           <exec executable="sed" output="./newfile">
             <arg>-e</arg>
             <arg>'s/bad/good/'</arg>
           </exec>

    Where does the input file belong in the Ant syntax?
    As an <arg>?  That doesn't seem to work.



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com


Re: unix redirection - how do you specify input files?

Posted by Bill Burton <bi...@progress.com>.
David Corbin wrote:
> 
> Bill Burton wrote:
> > >     Where does the input file belong in the Ant syntax?
> > >     As an <arg>?  That doesn't seem to work.
> >
> > The real question is, where does the input file belong in the sed syntax?
> > Sed will take input either from stdin or a file.  So just specify the file
> > after the pattern:
> >         <exec executable="sed" output="newfile">
> >           <arg value="-e"/>
> >           <arg value="s/bad/good/"/>
> >           <arg value="oldfile"/>
> >         </exec
> >
> A fine solution for sed, but what about other tools that ONLY deal with
> stdin (stupid though they may be).

Yes, that's a limitation with the <exec> task not allowing stdin to be
redirected.  One work around is to run the command through the shell:
	<exec executable="sh" output="newfile">
	  <arg line="-c &quot;sed 's/bad/good' < oldfile&quot;"/>
	</exexc>

For NT, it would be similar:
	<exec executable="cmd" os="Windows NT" output="newfile">
	  <arg line="/c &quot;some-command < oldfile&quot;"/>
	</exexc>

-Bill Burton

> 
> David Corbin
> Mach Turtle Technologies, Inc.
> http://www.machturtle.com
> dcorbin@machturtle.com

Re: unix redirection - how do you specify input files?

Posted by James Bucanek <su...@gloaming.com>.
At 2:57 PM -0500 12/21/00, David Corbin wrote:
>Bill Burton wrote:
>>  >     Where does the input file belong in the Ant syntax?
>>  >     As an <arg>?  That doesn't seem to work.
>>
>>  The real question is, where does the input file belong in the sed syntax?
>>  Sed will take input either from stdin or a file.  So just specify the file
>>  after the pattern:
>>          <exec executable="sed" output="newfile">
>>            <arg value="-e"/>
>>            <arg value="s/bad/good/"/>
>>            <arg value="oldfile"/>
>>          </exec
>>
>A fine solution for sed, but what about other tools that ONLY deal with
>stdin (stupid though they may be).

I usually solve this by creating a shell script that pipes the file 
to the command.  From Ant you would launch a shell, passing it the 
name of the script and it's arguments.

The other alternative would be to create your own Ant Task, and call 
Runtime.exec() yourself.  The returned Process object contains the 
input and output streams of the process.

__________________________________
James Bucanek
<ma...@gloaming.com>


Re: unix redirection - how do you specify input files?

Posted by David Corbin <dc...@machturtle.com>.
Bill Burton wrote:
> >     Where does the input file belong in the Ant syntax?
> >     As an <arg>?  That doesn't seem to work.
> 
> The real question is, where does the input file belong in the sed syntax?
> Sed will take input either from stdin or a file.  So just specify the file
> after the pattern:
>         <exec executable="sed" output="newfile">
>           <arg value="-e"/>
>           <arg value="s/bad/good/"/>
>           <arg value="oldfile"/>
>         </exec
> 
A fine solution for sed, but what about other tools that ONLY deal with
stdin (stupid though they may be).

David Corbin 		
Mach Turtle Technologies, Inc.
http://www.machturtle.com
dcorbin@machturtle.com

Re: unix redirection - how do you specify input files?

Posted by Bill Burton <bi...@progress.com>.
Hello,

Steve Dews wrote:
> 
> Hello,
> 
>     Here's what I'm trying to do:
> 
>            $ sed -e 's/bad/good/' < oldfile > newfile
> 
>     Here's what I've got in Ant:
> 
>            <exec executable="sed" output="./newfile">
>              <arg>-e</arg>
>              <arg>'s/bad/good/'</arg>
>            </exec>
> 
>     Where does the input file belong in the Ant syntax?
>     As an <arg>?  That doesn't seem to work.

The real question is, where does the input file belong in the sed syntax? 
Sed will take input either from stdin or a file.  So just specify the file
after the pattern:
	<exec executable="sed" output="newfile">
	  <arg value="-e"/>
	  <arg value="s/bad/good/"/>
	  <arg value="oldfile"/>
	</exec

However, you may find it easier to use Ant's <replace> task.  For
instance:
	<copy file="oldfile" tofile="newfile"/>
	<replace file="newfile" token="bad" value="good"/>

-Bill Burton

Re: unix redirection - how do you specify input files?

Posted by Stefan Schmitt <ss...@raleigh.ibm.com>.
From: "Steve Dews" <st...@hotmail.com>
Subject: unix redirection - how do you specify input files?


>     Here's what I'm trying to do:
>
>            $ sed -e 's/bad/good/' < oldfile > newfile
>
>     Here's what I've got in Ant:
>
>            <exec executable="sed" output="./newfile">
>              <arg>-e</arg>
>              <arg>'s/bad/good/'</arg>
>            </exec>
>
>     Where does the input file belong in the Ant syntax?
>     As an <arg>?  That doesn't seem to work.

Ok your syntax is wrong try this
<exec executable="sed" output="./newfile">
    <arg line="-e 's/bad/good/'"/>
</exec>
This should work. Take a deeper look at the manual avaible at
http://jakarta.apache.org/ant/jakarta-ant/docs/.

Yours Stefan S