如何确保 Ant 的 exec 任务的所有输出都转到 stdout? [英] How can I ensure all output from Ant's exec task goes to stdout?

查看:21
本文介绍了如何确保 Ant 的 exec 任务的所有输出都转到 stdout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ant exec 任务有一个输出属性,可用于告诉 Ant 输出的去向.我用它来将输出重定向到一个文件.问题是,如果我不对输出做一些事情,Ant 打印的内容就没有多大帮助 - 它不完整.

The Ant exec task has an output property which can be used to tell Ant where the output goes. I've used it to redirect the output to a file. The thing is, if I don't do something with the output, the stuff that Ant prints isn't that much of a help - it's not complete.

有没有办法将输出属性设置为System.out?

Is there someway of setting the output property to System.out?

推荐答案

在 Windows 上用 ant 的 applyexec 任务执行批处理文件时,我发现有特殊的某些 stdout 和 stderr 未被 ant 捕获的情况.(例如:如果您调用一个批处理文件,该文件又调用其他命令(如 node.exe),则来自子 node.exe 进程的 stdout 和 stderror 是丢了.)

When executing a batch file with ant's apply or exec tasks on Windows, I found there are special cases where some of the stdout and stderr is not captured by ant. (For example: if you call a batch file that in turn calls other commands (like node.exe), then the stdout and stderror from the child node.exe process is lost.)

我花了很长时间试图调试这个!似乎捕获了批处理文件的 stdout 和 stderr,但是 ant 以某种方式看不到批处理文件调用的命令.(也许是因为它们是单独的子进程).使用上面建议的 outputerror 属性没有帮助,因为只有 some 的 stdout 和/或 stderr 被捕获.

I spent a long time trying to debug this! It seems that the batch file's stdout and stderr is captured, however commands called by the batch file are somehow not seen by ant. (perhaps because they are separate child processes). Using the output and error attributes as suggested above doesn't help because only some of the stdout and/or stderr is captured.

我想出的解决方案(hack)是在命令末尾添加这些参数:

The solution I came up with (a hack) is to add these arguments at the end of the command:

<!--Next arg: forces node's stderror and stdout to a temporary file-->
<arg line=" &gt; _tempfile.out 2&lt;&amp;1"/>

<!--Next arg: If command exits with an error, then output the temporary file to stdout, -->
<!--delete the temporary file and finally exit with error level 1 so that    -->
<!--the apply task can catch the error if @failonerror="true"                -->
<arg line=" || (type _tempfile.out &amp; del _tempfile.out &amp; exit /b 1)"/>

<!--Next arg: Otherwise, just type the temporary file and delete it-->
<arg line=" &amp; type _tempfile.out &amp; del _tempfile.out &amp;"/>

因为这个hack只适用于windows,记得在applyexec<中添加@osfamily="windows"/代码> 任务.并为`@osfamily="unix" 等创建类似的任务,但没有这些额外的参数.

Because this hack only applies to windows, remember to add @osfamily="windows" to the apply or exec task. And create similar task(s) for `@osfamily="unix", etc but without these extra arguments.

这篇关于如何确保 Ant 的 exec 任务的所有输出都转到 stdout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆