You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Sayed, Irfan (Irfan)" <is...@avaya.com> on 2007/07/18 15:07:26 UTC

Execution of windows command in ant's build.xml

Hi All,
 
Need to execute windows 'cls' command in the Ant's build.xml file. 
 
Can somebody please help.
 
Regards
Irfan.
 
 

Re: Execution of windows command in ant's build.xml

Posted by cuillandre frederic <fr...@airweb.fr>.
check out this
http://ant.apache.org/manual/CoreTasks/exec.html

> Hi All,
>  
> Need to execute windows 'cls' command in the Ant's build.xml file. 
>  
> Can somebody please help.
>  
> Regards
> Irfan.
>  
> 

Frederic Cuillandre

+ 33 176616524
+ 33 661948720

frederic.cuillandre@airweb.fr
www.airweb.fr

Re: Execution of windows command in ant's build.xml

Posted by Dominique Devienne <dd...@gmail.com>.
On 7/18/07, Alec Fernandez <Al...@sas.com> wrote:
> Excellent clarifications gentleman, many thanks.
>
> You got me curious so I dug up a working example of quoting that I use.
>
> Try as I may, I can't seem to escape from the msdos command line processor.  Bill's  enduring gift to humanity.

At least for an interactive DOS session, the escape character is ^,
which I use for example to write at the DOS prompt: grep -r ClassName
--include=^*.cpp


>                   <!-- this doesn't seem to work on unix after all
>                   <arg value="@{cmd.line} &gt; ${logfile.fqp} 2&gt;&amp;1"/> -->

You'd need to use <arg line="">, not <arg value="">. --DD

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


RE: Execution of windows command in ant's build.xml

Posted by Alec Fernandez <Al...@sas.com>.
Excellent clarifications gentleman, many thanks.  

You got me curious so I dug up a working example of quoting that I use.  

Try as I may, I can't seem to escape from the msdos command line processor.  Bill's  enduring gift to humanity.

      <!-- Exec a command with spawn.  No return code checking possible. -->
      <macrodef name="execSpawnCmd">
         <attribute name="cmd"/>
         <attribute name="cmd.line" default=""/>
         <attribute name="dir" default=""/>
         <attribute name="logdir"/>
         <attribute name="logfile"/>
         <attribute name="callingTarget" default=""/>
       
         <sequential>
            <echo level="verbose" message="execSpawnCmd: cmd = @{cmd}"/>
            <echo level="verbose" message="execSpawnCmd: cmd.line = @{cmd.line}"/>
            <echo level="verbose" message="execSpawnCmd: dir = @{dir}"/>
            <echo level="verbose" message="execSpawnCmd: logdir = @{logdir}"/>
            <echo level="verbose" message="execSpawnCmd: logfile = @{logfile}"/>
            <echo level="verbose" message="execSpawnCmd: callingTarget = @{callingTarget}"/>


            <property name="logfile.fqp" location="@{logdir}/@{logfile}"/>
            <if><equals arg1="${os.localhost.type}" arg2="win"/><then>
               <exec executable="cmd" dir="@{dir}" spawn="true"> 
                  <arg value="/c"/>
                  <arg value="&quot;&quot;@{cmd}&quot; @{cmd.line} &gt; &quot;${logfile.fqp}&quot; 2&gt;&amp;1&quot;"/>
               </exec> 
            </then><elseif><equals arg1="${os.localhost.type}" arg2="unx"/><then>
               <exec executable="@{cmd}" dir="@{dir}" spawn="true">
                  <!-- this doesn't seem to work on unix after all
                  <arg value="@{cmd.line} &gt; ${logfile.fqp} 2&gt;&amp;1"/> -->
                  <arg value="@{cmd.line}"/>
               </exec> 
            </then></elseif></if>
          
         </sequential>
      </macrodef>

-----Original Message-----
From: Peter Reilly [mailto:peter.kitt.reilly@gmail.com] 
Sent: Wednesday, July 18, 2007 12:06 PM
To: Ant Users List
Subject: Re: Execution of windows command in ant's build.xml

On 7/18/07, Jack J. Woehr <jw...@absolute-performance.com> wrote:
>
> On Jul 18, 2007, at 9:55 AM, Peter Reilly wrote:
>
> >
> > Remember that a lot of directories have spaces in windows and this, 
> > combined with the multiple layers of quoting and interpretation 
> > (ant, Java, cmd and the other commands) mean that things may not 
> > work as expected.
>
> Entreprerneurial opportunity here for book, working title, 
> "Weirdnesses using open source software on Windows" :-)
That should be
"Weirdnesses using command line software on Windows"

Peter
>
>
> --
> Jack J. Woehr
> Director of Development
> Absolute Performance, Inc.
> jwoehr@absolute-performance.com
> 303-443-7000 ext. 527
>
>
>

---------------------------------------------------------------------
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


Re: Execution of windows command in ant's build.xml

Posted by Peter Reilly <pe...@gmail.com>.
On 7/18/07, Jack J. Woehr <jw...@absolute-performance.com> wrote:
>
> On Jul 18, 2007, at 9:55 AM, Peter Reilly wrote:
>
> >
> > Remember that a lot of directories have spaces in windows
> > and this, combined with the multiple layers of quoting and
> > interpretation
> > (ant, Java, cmd and the other commands)
> > mean that things may not work as expected.
>
> Entreprerneurial opportunity here for book, working title,
> "Weirdnesses using open source software on Windows" :-)
That should be
"Weirdnesses using command line software on Windows"

Peter
>
>
> --
> Jack J. Woehr
> Director of Development
> Absolute Performance, Inc.
> jwoehr@absolute-performance.com
> 303-443-7000 ext. 527
>
>
>

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


Re: Execution of windows command in ant's build.xml

Posted by "Jack J. Woehr" <jw...@absolute-performance.com>.
On Jul 18, 2007, at 9:55 AM, Peter Reilly wrote:

>
> Remember that a lot of directories have spaces in windows
> and this, combined with the multiple layers of quoting and
> interpretation
> (ant, Java, cmd and the other commands)
> mean that things may not work as expected.

Entreprerneurial opportunity here for book, working title,
"Weirdnesses using open source software on Windows" :-)


-- 
Jack J. Woehr
Director of Development
Absolute Performance, Inc.
jwoehr@absolute-performance.com
303-443-7000 ext. 527



Re: Execution of windows command in ant's build.xml

Posted by Peter Reilly <pe...@gmail.com>.
Do not forget that ant in written in java and
the exec argument uses Process - the Process
code is given the command line as a string, and adds
(in c)  in it's own quoting characters.

Always one should play around with simple ant scripts
to try to see what will work for the <exec> call.
Remember that a lot of directories have spaces in windows
and this, combined with the multiple layers of quoting and
interpretation
(ant, Java, cmd and the other commands)
mean that things may not work as expected.

Peter


On 7/18/07, Alec Fernandez <Al...@sas.com> wrote:
> Howdy folks,
>
> This from the exec doc:
>
> <!-- not tested -->
> <target name="help">
>   <exec executable="cmd">
>     <arg value="/c"/>
>     <arg value="&quot;dir;cls;set;cls;"/>
>   </exec>
> </target>
>
> I would recommend that you read the dos "man" pages on cmd start and call, they are quite useful.  Pay close attention to the /c /k and /s options if you are passing multiple commands and quotes are necessary.
>
> Cmd /? Yields a wealth of info, I've found the following snippet is particularly useful:
>
> If /C or /K is specified, then the remainder of the command line after
> the switch is processed as a command line, where the following logic is
> used to process quote (") characters:
>
>     1.  If all of the following conditions are met, then quote characters
>         on the command line are preserved:
>
>         - no /S switch
>         - exactly two quote characters
>         - no special characters between the two quote characters,
>           where special is one of: &<>()@^|
>         - there are one or more whitespace characters between the
>           the two quote characters
>         - the string between the two quote characters is the name
>           of an executable file.
>
>     2.  Otherwise, old behavior is to see if the first character is
>         a quote character and if so, strip the leading character and
>         remove the last quote character on the command line, preserving
>         any text after the last quote character.
>
> -----Original Message-----
> From: Sayed, Irfan (Irfan) [mailto:isayed@avaya.com]
> Sent: Wednesday, July 18, 2007 9:07 AM
> To: user@ant.apache.org
> Subject: Execution of windows command in ant's build.xml
>
> Hi All,
>
> Need to execute windows 'cls' command in the Ant's build.xml file.
>
> Can somebody please help.
>
> Regards
> Irfan.
>
>
>
> ---------------------------------------------------------------------
> 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


RE: Execution of windows command in ant's build.xml

Posted by Alec Fernandez <Al...@sas.com>.
Howdy folks,

This from the exec doc:

<!-- not tested -->
<target name="help">
  <exec executable="cmd">
    <arg value="/c"/>
    <arg value="&quot;dir;cls;set;cls;"/>
  </exec>
</target>

I would recommend that you read the dos "man" pages on cmd start and call, they are quite useful.  Pay close attention to the /c /k and /s options if you are passing multiple commands and quotes are necessary.  

Cmd /? Yields a wealth of info, I've found the following snippet is particularly useful:

If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic is
used to process quote (") characters:

    1.  If all of the following conditions are met, then quote characters
        on the command line are preserved:

        - no /S switch
        - exactly two quote characters
        - no special characters between the two quote characters,
          where special is one of: &<>()@^|
        - there are one or more whitespace characters between the
          the two quote characters
        - the string between the two quote characters is the name
          of an executable file.

    2.  Otherwise, old behavior is to see if the first character is
        a quote character and if so, strip the leading character and
        remove the last quote character on the command line, preserving
        any text after the last quote character.

-----Original Message-----
From: Sayed, Irfan (Irfan) [mailto:isayed@avaya.com] 
Sent: Wednesday, July 18, 2007 9:07 AM
To: user@ant.apache.org
Subject: Execution of windows command in ant's build.xml

Hi All,
 
Need to execute windows 'cls' command in the Ant's build.xml file. 
 
Can somebody please help.
 
Regards
Irfan.
 
 

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