You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Matt Reason <ma...@movielink.com> on 2003/04/04 23:23:00 UTC
Need help using exec to do "ls -rt1 | tail -1"
That command returns the name of the newest file in the directory. I
want to put that string into a property.
The exec task seems to hate the fact that one of my arguments is a pipe.
Does anyone have a workaround?
I think I've tried every possible permutation of this:
<target name="getNewest">
<exec dir="${sourcedir}" executable="ls"
outputproperty="theNewestFile">
<!--
<arg line="-rt1 | tail -1"/>
-->
<arg line="-rt1"/>
<arg line="|"/>
<arg line="tail"/>
<arg line="-1"/>
</exec>
<echo message="The newest file in ${sourcedir} is:
${theNewestFile}"/>
</target>
Re: Need help using exec to do "ls -rt1 | tail -1"
Posted by Martin <mg...@hotmail.com>.
try
'>' instead of '|'
Martin
----- Original Message -----
From: "Matt Reason" <ma...@movielink.com>
To: "Ant Users List" <us...@ant.apache.org>
Sent: Friday, April 04, 2003 2:23 PM
Subject: Need help using exec to do "ls -rt1 | tail -1"
That command returns the name of the newest file in the directory. I
want to put that string into a property.
The exec task seems to hate the fact that one of my arguments is a pipe.
Does anyone have a workaround?
I think I've tried every possible permutation of this:
<target name="getNewest">
<exec dir="${sourcedir}" executable="ls"
outputproperty="theNewestFile">
<!--
<arg line="-rt1 | tail -1"/>
-->
<arg line="-rt1"/>
<arg line="|"/>
<arg line="tail"/>
<arg line="-1"/>
</exec>
<echo message="The newest file in ${sourcedir} is:
${theNewestFile}"/>
</target>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Need help using exec to do "ls -rt1 | tail -1"
Posted by Herr Christian Wolfgang Hujer <Ch...@itcqis.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello Matt,
Am Freitag, 4. April 2003 23:23 schrieb Matt Reason:
> The exec task seems to hate the fact that one of my arguments is a pipe.
Seems so.
> Does anyone have a workaround?
I think it should work if you use sh as a command and pass your desired
command line as argument to parameter c:
sh -c "ls -rt1 | tail -1"
> I think I've tried every possible permutation of this:
>
> <target name="getNewest">
> <exec dir="${sourcedir}" executable="ls"
> outputproperty="theNewestFile">
> <!--
> <arg line="-rt1 | tail -1"/>
> -->
> <arg line="-rt1"/>
> <arg line="|"/>
> <arg line="tail"/>
> <arg line="-1"/>
> </exec>
> <echo message="The newest file in ${sourcedir} is:
> ${theNewestFile}"/>
> </target>
So you may try (didn't try myself)
<exec dir="${sourcedir}" executable="sh" outputproperty="theNewestFile">
<arg line="-c" />
<arg value="ls -rt1 | tail -1" />
</exec>
I hope this will work for you.
Bye
- --
ITCQIS GmbH
Christian Wolfgang Hujer
Geschäftsführender Gesellschafter
Telefon: +49 (0)89 27 37 04 37
Telefax: +49 (0)89 27 37 04 39
E-Mail: Christian.Hujer@itcqis.com
WWW: http://www.itcqis.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE+jhQxzu6h7O/MKZkRAgFOAJ4s84dyFfrLSQFOzBqVQZ9e797alwCffJmD
nVtzwHkiebjhMPwpodNdaBg=
=dTEa
-----END PGP SIGNATURE-----
Re: Need help using exec to do "ls -rt1 | tail -1"
Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 4 Apr 2003, Matt Reason <ma...@movielink.com> wrote:
> The exec task seems to hate the fact that one of my arguments is a
> pipe.
I won't repeat that this is due to the fact that pipe's are
interpreted by the shell 8-)
> Does anyone have a workaround?
Use <exec>'s output attribute to write the result of ls to a temporary
file and read this file into a property using <loadfile> and a nested
TailFilter.
Stefan
Re: Need help using exec to do "ls -rt1 | tail -1"
Posted by Jesse Stockall <je...@cryptocard.com>.
On Friday, April 4, 2003, at 04:23 PM, Matt Reason wrote:
>
>
> The exec task seems to hate the fact that one of my arguments is a
> pipe.
>
> Does anyone have a workaround?
Shot in the dark, but try 'vmlauncher=false', this will force exec to
use a shell, not Runtime.exec() to run the commands.
Jesse Stockall - jesse@cryptocard.com
CRYPTOCard Corp.
Re: Need help using exec to do "ls -rt1 | tail -1"
Posted by Matt Benson <gu...@yahoo.com>.
The problem with pipes is that they are part of the
shell command. One thing you might try is to make
your executable a shell, with ls et al as arguments.
Also, you could try the shell script task, pretty much
the same idea. Or, you could send the exec output to
a file, then load it into a property using <loadfile>
with a nested filterchain consisting of a tail filter
with lines=1.
-Matt
--- Matt Reason <ma...@movielink.com> wrote:
>
> That command returns the name of the newest file in
> the directory. I
> want to put that string into a property.
>
> The exec task seems to hate the fact that one of my
> arguments is a pipe.
>
> Does anyone have a workaround?
>
> I think I've tried every possible permutation of
> this:
>
> <target name="getNewest">
> <exec dir="${sourcedir}" executable="ls"
> outputproperty="theNewestFile">
> <!--
> <arg line="-rt1 | tail -1"/>
> -->
> <arg line="-rt1"/>
> <arg line="|"/>
> <arg line="tail"/>
> <arg line="-1"/>
> </exec>
> <echo message="The newest file in
> ${sourcedir} is:
> ${theNewestFile}"/>
> </target>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
>
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com