views:

1086

answers:

3

How can I call a batch file inside a nant script??? (Maybe having a target that calls the batch file).

A: 

Use the exec task.

James L
You may also have to use cmd /c yourbatch.cmd since nant probably doesn't know which program executes batch files.
Joey
In my tests, cmd /c was not necessary. Just provide the batch file name and like Haugholt said, set the basedir if needed.
Robert Claypool
+1 for the cmd /c hint. Thanks!
Peter Bernier
+3  A: 

That's pretty easy, actually - i'll try to illustrate:

 <target name="run-command">
   <exec program="ConsoleTest.exe" basedir="${test.dir}">
     <arg value="-cp" />
   </exec>
 </target>

The basedir is optional, it specifies where to run the program from. But if your program is on the path (like ping), you probably don't have to worry about it.

Have a look at the official documentation as well :)

Haugholt
+1  A: 

Before dropping to a batch file have you considered the tasks in nantcontrib? I needed to smoosh some little javascript files together and was going to use a batch file, but it turns out that nantcontrib has a concat task, for example.

robaker