ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: [solution] Need help using exec to do "ls -rt1 | tail -1"
Date Mon, 07 Apr 2003 22:16:54 GMT
I'm surprised... the 'value' attribute quotes it's value if it contains any
spaces, and if you say it doesn't, it's a bug. Are you sure you didn't try
it with the 'line' attribute, as your example showed? These two attributes
behave differently. Running with the -verbose (or -debug) flag will show the
actual command executed. It should work as I wrote it (I think!) --DD

-----Original Message-----
From: Matt Reason [mailto:matt.reason@movielink.com] 
Sent: Monday, April 07, 2003 5:13 PM
To: Ant Users List
Subject: RE: [solution] Need help using exec to do "ls -rt1 | tail -1"



You would think that'd work, but it doesn't.

Trust me - I've done them both.

Ant needs to pass a string with quotes in it to the sh executable.

Matt

-----Original Message-----
From: Dominique Devienne [mailto:DDevienne@lgc.com] 
Sent: Monday, April 07, 2003 12:31 PM
To: 'Ant Users List'
Subject: RE: [solution] Need help using exec to do "ls -rt1 | tail -1"


This should also work, and the quoting's done by Ant:

<exec dir="${sourcedir}" executable="sh" ...>
  <arg value="-c"/>
  <arg value="ls -rt1 | tail -1"/>
</exec>

It's a bit easier on the eyes IMHO. --DD

-----Original Message-----
From: Matt Reason [mailto:matt.reason@movielink.com] 
Sent: Monday, April 07, 2003 2:28 PM
To: Ant Users List
Subject: [solution] Need help using exec to do "ls -rt1 | tail -1"


Thanks to everyone for all the input.  I had no idea the pipe was
interpreted by the shell.

With that in mind, I got it to work.  Here is how to do it:

<target name="getNewest">
        <exec dir="${sourcedir}" executable="sh"
outputproperty="theNewestFile">
                <arg line="-c &quot;ls -rt1 | tail -1&quot;"/>
        </exec>
        <echo message="The newest file in ${sourcedir} is:
${theNewestFile}"/> 
</target>

NOTE: You have to put the actual command in quotes (&quot).

Matt

Mime
View raw message