Bug 53506 - output is duplicated when using redirector inside exec
Summary: output is duplicated when using redirector inside exec
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.8.1
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
Depends on:
Reported: 2012-07-04 07:57 UTC by Martin Stumpf
Modified: 2020-02-21 08:30 UTC (History)
2 users (show)

Java source that outputs 2 lines on stdout and stderr (258 bytes, text/plain)
2020-02-21 08:16 UTC, Alex R.
Ant script that showcases the problem (970 bytes, text/xml)
2020-02-21 08:18 UTC, Alex R.

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Stumpf 2012-07-04 07:57:02 UTC
Using exec together with redirector and not using the error attribute leads to a duplication on stdout (each line is duplicated).

                     <exec executable="@{executable}" 
                           output = "@{logfile}"
                           alwayslog = "true"
                           append = "true"
Comment 1 Stefan Bodewig 2014-03-03 17:19:22 UTC
doesn't seem to happen for me.  Can you provide an example build file that demonstrates the behavior?
Comment 2 jakub.neubauer 2014-04-11 11:19:58 UTC
Hi, I'm facing this issue too. But when I run it from console, it works, but when I just redirect the output of the ant (on the commandline, not with any option in build.xml), the error output is duplicated
Comment 3 Kostas Filios 2017-07-24 15:50:08 UTC
I just reproduced this issue using 1.9.6

It turns out there's a workaround. Here's what produces duplicate output:

    <redirector output="logfile"
                append="true" />

Here's what doesn't (I've added the error="" to point to the exact same file):

    <redirector output="logfile"
                append="true" />

Instead of adding error="" you can also add errorproperty="". Generally, just make sure you don't only provide output="", as it will produce duplicate output to the console when combined with alwayslog="true".
Comment 4 Alex R. 2020-02-21 08:16:50 UTC
Created attachment 37032 [details]
Java source that outputs 2 lines on stdout and stderr
Comment 5 Alex R. 2020-02-21 08:18:07 UTC
Created attachment 37033 [details]
Ant script that showcases the problem
Comment 6 Alex R. 2020-02-21 08:25:11 UTC
Confirming this bug on Windows 7, Ant 1.10.5.

Use case: Feed <exec>'s stdout and stderr both into the Ant log as well as an outputproperty.

Configuration: Use <redirector alwayslog="true" logError="false" outputproperty="myoutput"/> within the <exec> task.

Problem: Each stderr line occurs twice in the Ant log, but should occur only once. stdout on Ant log is fine, i.e. only occurs once. stderr and stdout in the outputproperty are fine.

Reproduction: Compile the attached DemoOutErr.java into a runnable JAR named DemoOutErr.jar, then run the attached Ant script demouterr.xml. The Java outputs 2 lines on stdout and stderr. The Ant script <exec>s the jar and showcases the problem.


C:\temp>ant -f demoouterr.xml
Buildfile: C:\temp\demoouterr.xml

     [exec] Hello on output
     [exec] News on output
     [exec] Hello on error
     [exec] News on error
     [exec] Hello on error
     [exec] News on error
     [echo] Contents of myoutput:
     [echo] Hello on output
     [echo] News on output
     [echo] Hello on error
     [echo] News on error

Total time: 0 seconds
Comment 7 Alex R. 2020-02-21 08:30:48 UTC
The workaround that Kostas Filios mentions, also puts stdout and stderr both on the Ant log, but feeds stdout and stderr to different properties. The same can be achieves by using just an outputproperty, but setting logError="true".

In these circumstances, the stderr shows only once on the Ant log, as it should.

However, if you need to feed stdout and stderr into the same property, the error persists.