Nant cmd.exe redirection creating file called ‘program’ on c:\ drive

command linecontinuous integrationnant

I have NAnt script which as part of its project calls a batch file using the following task:

<target name="makeplane">   
  <exec program="C:\WINDOWS\system32\CMD.EXE" 
      commandline="/C ${make.file} &gt; ${make.log}"          
      verbose="false" 
      workingdir="${make.dir}" 
      basedir="${make.dir}">         
      </exec>
    <delete>
      <fileset basedir="c:\">
        <include name="program" />
      </fileset>
    </delete>
</target>

Unfortunately i dont have control over the contents on the batch file and it spews out a lot of garbage onto the screen which is of no use in the log. So to get around this im redirecting the output from the bat file to a text file using the

 &gt; ${make.log}

part which equates to "> log.txt".

This redirection seems to create a file called "program" on the C drive and messes up all sorts of services and windows generally doesnt like it. To get around this Im manually deleting this file after the bat file has executed.

The problem is i now need to run a similar task for another project entirely and if they run at the same time then the first will lock the file called "program" and the second will fail. Not exactly a great situation for Continuous integration.

I searched on the net but because the file is called program i get all sorts of rubbish results. Anyone got any ideas on a work around. I tried the output parameter on the exec task but the issue remains the same.

Best Answer

If the file path to the log contains spaces, one generally would want to surround the path in quotes. In order to do this in nant one can use the &quot; entity.

It sounds like this is what's happening in your particular situation. Therefore, if you change your example to the following I think things should work as expected.

<target name="makeplane">   
    <exec program="C:\WINDOWS\system32\CMD.EXE" 
        commandline="/C ${make.file} &gt; &quot;${make.log}&quot;"          
        verbose="false" 
        workingdir="${make.dir}" 
        basedir="${make.dir}">         
    </exec>
</target>
Related Topic