views:

1247

answers:

3

Hi,

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.

+1  A: 

Usually this happens because the script is trying to create a file with a long file name with space in it (c:\program files in your case), but it is not using quotes around the long file name.

Franci Penov
Doh, why didnt i think of this earlier.
Kaius
+1  A: 

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>
Scott Saad
+1 I had implemented a fix before you posted, but you would have fixed it with this answer.
Kaius
A: 

Here is what I did. I think it is a bit cleaner for complex commands.

<property name="cmd.label" value="\${ss.previous.label}@$Project.SSPath" />
<echo message="Getting $Project.Name source code with label \${cmd.label}" />
<property name="cmd" value="&quot;\${tfs.root}\tf.exe&quot; get $Project.SSPath &quot;/version:L\${cmd.label}&quot; /force /recursive /noprompt"/>
<exec program="cmd.exe"
  workingdir="\${shadow.dir}"
  failonerror="true"
  verbose="true">
 <arg value="/c" />
 <arg value="&quot;\${cmd}&quot;" />
 <arg value="> nul" />
</exec>
Chad Juliano