我怎样才能确保Ant的EXEC任务,所有输出到标准输出? [英] How can I ensure all output from Ant's exec task goes to stdout?

查看:476
本文介绍了我怎样才能确保Ant的EXEC任务,所有输出到标准输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ant的 EXEC 任务有哪些可以用来告诉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?

推荐答案

在执行与批处理文件Ant的适用 EXEC 在Windows的任务,我发现还有有些地方的输出和错误不被捕获蚂蚁的特殊情况。 (例如:如果你调用一个批处理文件,依次调用其他的命令(如 node.exe ),然后从孩子的标准输出和stderror node.exe 过程中丢失。)

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

我花了很长时间试图调试此!看来这个批处理文件的输出和错误被捕获,但命令批处理文件调用不知何故没有蚂蚁看见。 (可能是因为它们是独立的子进程)。使用输出错误属性作为上述建议没有帮助,因为只有中的部分的标准输出和/或标准错误被捕获。

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.

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

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;"/>

由于此的破解的仅适用于Windows,记得要加 @ osfamily =窗口适用 EXEC 任务。而对于`@ osfamily =UNIX等,但如果没有这些额外的参数创建类似的任务(S)。

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任务,所有输出到标准输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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