SecretDeveloper
SecretDeveloper

Reputation: 3140

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

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.

Upvotes: 1

Views: 5911

Answers (3)

Chad Juliano
Chad Juliano

Reputation: 21

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>

Upvotes: 0

Scott Saad
Scott Saad

Reputation: 18372

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>

Upvotes: 3

Franci Penov
Franci Penov

Reputation: 76011

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.

Upvotes: 1

Related Questions