How to redirect stdout stderr in an ant script?

2019-04-06 02:35发布

I am triggering an ant script (via cruise control), and would like to be able to dump the std out and std err for a particular ant target to a plain text file.

Yes, I am aware that cruise control already does maintain an XML log file containing this information (among many other things), but for portability reasons, I need this to happen from the ant script itself.

Is this possible, and if so, how to do it?

Many thanks!

3条回答
时光不老,我们不散
2楼-- · 2019-04-06 03:19

It's easy:

ant -logfile <logfile> <command>

And you can also say to ant shut up:

ant -q <command>

It worked fine to me.

查看更多
劳资没心,怎么记你
3楼-- · 2019-04-06 03:26

The recorder task may be able to do what you want:

<record name="log.txt" action="start"/>
...
<record name="log.txt" action="stop"/>

Beyond that, certain tasks (exec, java, etc) offer this functionality by themselves (usually by means of output and error arguments)

查看更多
不美不萌又怎样
4楼-- · 2019-04-06 03:31

Try this:

<java classname="some.package.Class"
    fork="yes"
    output="stdouterr.txt">
    ...
</java>

stdouterr.txt will contain both stdout and stderr

<java classname="some.package.Class"
    fork="yes"
    output="stdout.txt"
    error="stderr.txt">
    ...
</java>

stdout.txt and stderr.txt will contain stdout and stderr respectively

From my experience, the record task tends to fail when the ant script is run on cruise control, due to file access permissions (if someone can tell me how to fix that I'll be a happy man).

HTH

查看更多
登录 后发表回答