How can I call a batch file inside a nant script??? (Maybe having a target that calls the batch file).
Asked
Active
Viewed 7,029 times
3 Answers
8
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
- 837
- 9
- 15
2
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
- 1,028
- 7
- 11
1
-
3You may also have to use cmd /c yourbatch.cmd since nant probably doesn't know which program executes batch files. – Joey Mar 10 '09 at 22:54
-
@Joey: The `cmd /c` hint is crucial; only like that does it become possible to run something of which you don't know yet whether it is an exe or a bat file. If you write an answer with that, I will upvote it. – O. R. Mapper Aug 18 '15 at 18:06
-
@Joey: Wait, with `cmd /c` in place, NAnt will not be able to run the same build script on Linux, right? – O. R. Mapper Aug 18 '15 at 18:10
-
It'd be difficult to use the exact same script on Linux anyway, so just distinguish by platform in two different tasks. – Joey Aug 18 '15 at 18:47
-
@Joey: I'm not sure what would be difficult about that, but I've asked about the issue in a [separate question](http://stackoverflow.com/questions/32080350/running-a-native-executable-or-a-batch-file-found-in-the-search-path-from-platfo). – O. R. Mapper Aug 18 '15 at 18:51