ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jhoomshar...@netscape.net
Subject Re: Excute shell command
Date Wed, 15 Jul 2009 09:07:28 GMT

I combined xmltask and ant-contrib's shellscript like this

<target name="readme-replace" depends="init">
????? 
?? <copy file="${src.xml.path}/pom.xml" todir="${dest.xml.path}"/>
?
???? <!-- active-directory -->
???? <xmltask source="${act.dir.path}/pom.xml">
???????? <copy path="//:project/:version[1]/text()" property="active-dir"/>
???? </xmltask>

???? <property name="act-dir" value="${active-dir}"/>
??????????? <echo message="ACTIVE: ${act-dir}"/>


???? <shellscript shell="bash">
??????????????? KAR=`echo ${act-dir} | awk -F. '{print $1}'`
??????????????? MAR=`echo ${act-dir} | awk -F. '{print $4}'`
???? echo "KAR: $KAR"
???? echo "MAR: $MAR"
???? </shellscript>

??<echo message="First: ${KAR}"/>
??<echo message="Fourth: ${MAR}"/>
</target>

I am able to achieve what I want i.e. able to get values in variables "KAR" and "MAR" but
the problem here is I am unable to use variable "$KAR" and "$MAR" outside of <shellscript>
task.
you can see "echo" task outside shellscript task is not able to get the value of "KAR" and
"MAR"
Can anyone give me an idea on how I can use "KAR" and "MAR" outside of shellscript task?


-----Original Message-----
From: David Weintraub <qazwart@gmail.com>
To: Ant Users List <user@ant.apache.org>
Sent: Tue, Jul 14, 2009 11:20 pm
Subject: Re: Excute shell command




I could simply tell you to use the exec task:

<exec executable="/bin/bash"
    outproperty="KAR">
    <arg line="echo $var | awk -F '{print $4}'"/>
</exec>

However, there must be a better way to get this particular information:

You can use <property env="ENV"/>, and that would put the value of $var into
a property called "ENV.var". Now, to parse it a bit. That could be done with
resources and token filtering. See <
http://ant.apache.org/manual/CoreTypes/filterchain.html> and <
http://ant.apache.org/manual/CoreTypes/filterchain.html#tokenfilter> for
more information.

If ${var} came from a file that you're now attempting to parse, it should be
fairly easy to setup a filter reader on a file, find the line, and pull out
the fourth value on that line. Otherwise, you'll be attempting to parse a
property, and that's a bit harder to setup.

On Tue, Jul 14, 2009 at 8:53 AM, <jhoomsharabi@netscape.net> wrote:

> Hi All,
>
> I am stuck to shell command execution in my build.xml file, I want to
> execute the following command from my build.xml file:
>
> KAR=`echo $var | awk -F. '{print $4}'`
>
> Can anyone help me out in this?
>
> Thanks in advance.
>



-- 
David Weintraub
qazwart@gmail.com


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message