Bug 53506

Summary: output is duplicated when using redirector inside exec
Product: Ant Reporter: Martin Stumpf <martinst>
Component: Core tasksAssignee: Ant Notifications List <notifications>
Status: NEW ---    
Severity: normal CC: alexander, jakub.neubauer
Priority: P2    
Version: 1.8.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Java source that outputs 2 lines on stdout and stderr
Ant script that showcases the problem

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}" 
                          dir="@{dir}"
                          resultproperty="@{resultproperty}"              
                          failonerror="@{failonerror}"
                          timeout="@{timeout}">
                          <redirector 
                           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:

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


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

<exec>
    <redirector output="logfile"
                error="logfile"
                alwayslog="true"
                append="true" />
</exec>


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.

Output:

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

demo:
     [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]
     [echo] Contents of myoutput:
     [echo] Hello on output
     [echo] News on output
     [echo] Hello on error
     [echo] News on error

BUILD SUCCESSFUL
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.