Nant cmd.exe 重定向创建名为“program”的文件; 在 c:\ 驱动器上

发布于 2024-07-14 03:11:32 字数 937 浏览 4 评论 0原文

我有 NAnt 脚本,作为其项目的一部分,使用以下任务调用批处理文件:

<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>

不幸的是,我无法控制批处理文件上的内容,它会在屏幕上吐出大量垃圾,这在日志中没有用处。 因此,为了解决这个问题,我使用

 &gt; ${make.log}

相当于“> log.txt”的部分将bat文件的输出重定向到文本文件。

这种重定向似乎在 C 驱动器上创建了一个名为“程序”的文件,并搞乱了各种服务,而 Windows 通常不喜欢它。 为了解决这个问题,我在执行 bat 文件后手动删除该文件。

问题是我现在需要为另一个项目完全运行类似的任务,如果它们同时运行,那么第一个将锁定名为“程序”的文件,第二个将失败。 对于持续集成来说,这并不是一个很好的情况。

我在网上搜索,但因为该文件被称为程序,所以我得到了各种垃圾结果。 任何人对解决方法有任何想法。 我尝试了 exec 任务的输出参数,但问题仍然存在。

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} > ${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

 > ${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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦里°也失望 2024-07-21 03:11:32

如果日志的文件路径包含空格,通常需要用引号将该路径引起来。 为了在 nant 中执行此操作,可以使用 " 实体。

听起来这就是您的特定情况下发生的情况。 因此,如果您将示例更改为以下内容,我认为事情应该按预期进行。

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

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 " 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} > "${make.log}""          
        verbose="false" 
        workingdir="${make.dir}" 
        basedir="${make.dir}">         
    </exec>
</target>
趁微风不噪 2024-07-21 03:11:32

通常会发生这种情况,因为脚本试图创建一个文件名较长且包含空格的文件(在您的情况下为 c:\program files ),但事实并非如此在长文件名周围使用引号。

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.

贩梦商人 2024-07-21 03:11:32

这就是我所做的。 我认为对于复杂的命令来说它更干净一些。

<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=""\${tfs.root}\tf.exe" get $Project.SSPath "/version:L\${cmd.label}" /force /recursive /noprompt"/>
<exec program="cmd.exe"
  workingdir="\${shadow.dir}"
  failonerror="true"
  verbose="true">
 <arg value="/c" />
 <arg value=""\${cmd}"" />
 <arg value="> nul" />
</exec>

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=""\${tfs.root}\tf.exe" get $Project.SSPath "/version:L\${cmd.label}" /force /recursive /noprompt"/>
<exec program="cmd.exe"
  workingdir="\${shadow.dir}"
  failonerror="true"
  verbose="true">
 <arg value="/c" />
 <arg value=""\${cmd}"" />
 <arg value="> nul" />
</exec>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文