Nant cmd.exe 重定向创建名为“program”的文件; 在 c:\ 驱动器上
我有 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>
<delete>
<fileset basedir="c:\">
<include name="program" />
</fileset>
</delete>
</target>
不幸的是,我无法控制批处理文件上的内容,它会在屏幕上吐出大量垃圾,这在日志中没有用处。 因此,为了解决这个问题,我使用
> ${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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果日志的文件路径包含空格,通常需要用引号将该路径引起来。 为了在 nant 中执行此操作,可以使用
"
实体。听起来这就是您的特定情况下发生的情况。 因此,如果您将示例更改为以下内容,我认为事情应该按预期进行。
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.
通常会发生这种情况,因为脚本试图创建一个文件名较长且包含空格的文件(在您的情况下为
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.这就是我所做的。 我认为对于复杂的命令来说它更干净一些。
Here is what I did. I think it is a bit cleaner for complex commands.