Ant exec task

20 May 2008

To execute a system command from Ant, exec is used. Since different operating systems have different commands, therefore OS commands (if used), will restrict the build script to a particular operating system.

One cannot interact with the forked program and if any attempt to read input in the forked program is made, an EOF (-1) will be thrown.

The task delegates to Runtime.exec which in turn apparently calls ::CreateProcess. Generally, batch files (.bat) cannot by executed directly. You need to execute the command shell executable cmd using the /c switch.

<target name="help">
  <exec executable="cmd">
    <arg value="/c"/>
    <arg value="ant.bat"/>
    <arg value="-p"/>
  </exec>
</target>

Review the following example:

<exec dir="${src}" executable="cmd.exe" os="Windows 2000" output="dir.txt">
  <arg line="/c dir"/>
</exec>

Let me briefly explain the parameters of exec:

dir - specifies the directory in which the command should be executed.
executable - specifies the command to execute without any command line arguments.
os - specifies the Operating Systems on which the command may be executed.
output - specifies the file to which the output of the command should be redirected.

Hope this helps.

del.icio.us:Ant exec task  digg:Ant exec task  spurl:Ant exec task  wists:Ant exec task  simpy:Ant exec task  newsvine:Ant exec task  blinklist:Ant exec task  furl:Ant exec task  reddit:Ant exec task  fark:Ant exec task  blogmarks:Ant exec task  Y!:Ant exec task  smarking:Ant exec task  magnolia:Ant exec task  segnalo:Ant exec task  gifttagging:Ant exec task

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Ant exec task

Leave a Reply