ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rhino" <rhi...@sympatico.ca>
Subject Re: Running Ant from a Windows batch file
Date Tue, 19 Oct 2004 14:57:55 GMT
MessageI was hoping it would be that simple ;-)

Thanks, my batch file now works perfectly!

Rhino

  ----- Original Message ----- 
  From: Dick, Brian E. 
  To: Ant Users List 
  Sent: Tuesday, October 19, 2004 10:48 AM
  Subject: RE: Running Ant from a Windows batch file


  Since the ant command on Windows is a batch file, you have to "call" it when you use it
from another batch file. Change you batch file to

  call ant -f cond3.xml


    -----Original Message-----
    From: Rhino [mailto:rhino1@sympatico.ca] 
    Sent: Tuesday, October 19, 2004 10:44 AM
    To: ant-user
    Subject: Running Ant from a Windows batch file



    I would like to be able to run an Ant (1.6.1) script from a Windows batch file on XP.
Unfortunately, my Ant script contains <input> tasks and they are messing me up. 

    Here is my batch file, cond3.bat:
    ------------------------------------
    rem Batch file to run an Ant script.

    rem This variable is the drive that contains the executable program. 
    set progdrive=d:

    rem This variable sets the path to the script.
    set Script=eclipse\workspace\resume\xml

    rem Get into the directory containing the program.
    %progdrive%
    cd %Script%

    rem This command runs the program.
    ant -f cond3.xml

    pause
    ------------------------------------

    This is my Ant script:

    ------------------------------------
    <?xml version="1.0"?>

    <project name="cond3" default="end" basedir=".">

    <!--==================================================================

    Determine which server is the target.

    ==================================================================-->

    <target name="getserver" description="Determine which server is the target">

    <input message="Which server should receive the files? 1. Foo 2. Bar 3. Test" 

    validargs="1,2,3"

    addproperty="server.choice" 

    defaultvalue="2"/>

    <condition property="servername" value="foo">

    <equals arg1="${server.choice}" arg2="1"/>

    </condition>

    <condition property="servername" value="bar">

    <equals arg1="${server.choice}" arg2="2"/>

    </condition>

    <condition property="servername" value="test">

    <equals arg1="${server.choice}" arg2="3"/>

    </condition> 

    </target> 

    <!--==================================================================

    Load the properties file for the appropriate server.

    ==================================================================-->

    <target name="getprops" depends="getserver" description="Get the appropriate properties
file depending on the server which was chosen">

    <property file="server.${servername}.properties"/>

    </target>

    <!--==================================================================

    Get the userid and password for the desired server.

    ==================================================================-->

    <target name="getlogin" depends="getprops" description="Get userid and password for
server.">

    <input message="Please supply the userid for the ${server} server:" addproperty="userid"
defaultvalue="dougb"/>

    <input message="Please supply the password for the ${server} server:" addproperty="password"
defaultvalue="dougbpw"/>

    </target> 

    <!--==================================================================

    Execute the appropriate upload target, depending on which server 

    was chosen.

    ==================================================================-->

    <target name="upload" depends="getlogin" description="Upload to the selected server.">

    <antcall target="upload-${servername}"/> 

    </target>

    <!--==================================================================

    Upload to the 'foo' server.

    ==================================================================-->

    <target name="upload-foo" description="Upload to the foo server.">

    <echo message="Uploading to foo...."/>

    <echoproperties prefix="server"/>

    </target>

    <!--==================================================================

    Upload to the 'bar' server.

    ==================================================================-->

    <target name="upload-bar" description="Upload to the bar server.">

    <echo message="Uploading to bar...."/>

    <echoproperties prefix="server"/>

    </target>

    <!--==================================================================

    Upload to the 'test' server.

    ==================================================================-->

    <target name="upload-test" description="Upload to the test server.">

    <echo message="Uploading to test...."/>

    <echoproperties prefix="server"/>

    </target>

    <!--==================================================================

    Display a message to the user.

    ==================================================================-->

    <target name="end" depends="upload" description="Display a message.">

    <echo message="Uploads to server ${servername} are complete."/>

    </target>

    </project>

    ------------------------------------

    So far my script works fine when run from a batch file except that the command window
closes very quickly upon completion of the script and the user can't see the message generated
by the 'end' target, even though I have a Windows 'pause' command at the end of the batch
file. The 'pause' command works on other batch files I've written so I don't see why it doesn't
in this case.

    As a workaround, I tried changing the last lines of the batch file to say:

    ant -f cond3.xml > cond3.out
    notepad cond3.out

    but this doesn't work properly either. In this case, the script starts fine but the prompts,
like "Which server should receive the files? 1. Foo 2. Bar 3. Test"  from the input task don't
appear in the command window so the user doesn't understand what the command window is waiting
for.

    Does anyone know how I can have my cake and eat it too, in other words run Ant from a
batch file, see the prompts for inputs, and see the output messages from Ant?


    Rhino
    ---
    rhino1 AT sympatico DOT ca
    "There are two ways of constructing a software design. One way is to make it so simple
that there are obviously no deficiencies. And the other way is to make it so complicated that
there are no obvious deficiencies." - C.A.R. Hoare


------------------------------------------------------------------------------


  ---------------------------------------------------------------------
  To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
  For additional commands, e-mail: user-help@ant.apache.org
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message