nantnantcontrib

How do I use internal commands (Command.com) from NAnt? ("type" etc)


On windows systems, certain dos commands don't have executables that can be explicitly called via NAnt's exec task. (I'm talking specifically about commands that are part of Command.com)

A complete list can be found here. While some of the more useful commands can be achieved with NAnt or NAntContrib tasks (copy, move, rename etc), some (such as 'type') cannot.

How can you execute these commands as part of a build? For example, using a wildcard, how can I easliy display the contents of a log file from an external command executed by my build (so that the external command's log file contents will become echoed into the build's log file)


Solution

  • Internal commands can be called using the exec task in the following manner :

    <exec workingdir="${dir}" program="cmd" commandline="/c <command/> <arguments/>" />
    

    For the scenario in the question (where the log's filename is based on the current time, partway through the build), rather than parsing/scanning for the filename, loading it into a property and then echoing it, you could echo log contents with the following task :

    <exec program="cmd" workingdir="${dir}" commandline="/c type *.log" />