ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: Problems with exec tag
Date Fri, 01 Sep 2006 07:30:05 GMT
Maybe a slightly different approach ...

<project name="test" basedir="." default="main" xmlns:ac="antlib:net/sf/antcontrib">
    <property name="exec.file" location="exec.txt"/>

	<!-- some test data -->    
	<mkdir dir="c:/temp/path with blank"/>
	<echo file="c:/temp/path with blank/file.txt" message="c:/temp/path with blank/file.txt"/>
    <concat destfile="${exec.file}">
        notepad.exe c:\boot.ini
        calc.exe     
    </concat>
    
    <target name="main">
        <!-- load the "command" - one per line -->
        <loadfile property="forExecute" srcfile="${exec.file}">
            <filterchain>
                <tokenfilter>
                    <!-- trim the whitespaces at the begin and end -->
                    <linetokenizer/>
                    <replaceregex pattern="^\s*" replace=""/>
                    <replaceregex pattern="\s*$" replace=""/>
                    <!-- ignore empty lines -->
                    <ignoreblank/>
                </tokenfilter>
            </filterchain>
        </loadfile>
        <!-- use 'for' for avoiding additional targets; use 'line.separator' as separator
-->
        <ac:for list="${forExecute}" delimiter="${line.separator}" param="cmdLine">
            <sequential>
                <!-- split the commandline into command and args; CAUTION: cant handle
paths with blanks -->
                <ac:propertyregex override="true" input="@{cmdLine}" regexp="(.*) +(.*)"
property="cmd"  select="\1" defaultValue="@{cmdLine}"/>
                <ac:propertyregex override="true" input="@{cmdLine}" regexp="(.*) +(.*)"
property="args" select="\2" defaultValue=""/>
                <!-- execute the command -->
                <exec executable="${cmd}">
                    <arg line="${args}"/>
                </exec>
            </sequential>
        </ac:for>
    </target>
    
</project>    



Jan 

>-----Urspr√ľngliche Nachricht-----
>Von: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de] 
>Gesendet: Freitag, 1. September 2006 08:51
>An: user@ant.apache.org
>Betreff: AW: Problems with exec tag
>
>Your script works for me ...
>
><project name="test" basedir="." default="main">
>    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
>
>    <target name="main">
>    	<property name="src.file.head" value="notepad.exe;notepad.exe"/>
>    	<foreach list="${src.file.head}" delimiter=";" param="src.file"
>target="doExec" inheritall="true"/>
>    </target>
>
>    <target name="doExec">
>    	<echo message=" ${src.file}"/>
>    	<exec executable="${src.file}" failonerror="true"
>failifexecutionfails="false">
>    	</exec>
>    </target>
>    
></project>    
>
> 
>
>>I put the ant file below and the content of the test12.txt is // test 
>>exec file notepad.exe; notepad.exe
>
>
>Not sure about the blank after ';' ....
>
>
>Jan
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
>additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message