ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rich Wagner" <>
Subject Tasks' "output" attributes & merged stdout/stderr issues
Date Mon, 28 Apr 2003 21:06:47 GMT
Hi Folks,

With both the "java" and the "exec" tasks, it seems that when the 
"output={out_file}" attribute is used that both the stdout and the stderr 
end up in the "out_file"...

In my opinion, it'd be better if there were more options.  That is, why not 
let "java" and "exec" accept two more attributes, (say) "stdout={file1}" and 
"stderr={file2}" ?  The "stdout" attribute would ONLY capture stdout output; 
likewise for the "stderr" attribute.

The reason I'm suggesting that is two-fold:

First, when I recently used "output" for an "exec" task (involving the 
invocation of a Windows "*.cmd" script), I noticed that the order of the 
stdout and stderr output lines, as produced by the CMD script, was NOT being 
preserved.  The order of the stdout lines by themselves was fine, and the 
order of the stderr was fine, too.  No, it was how the stdout and stderr 
lines were MERGED in the "exec" tasks output that was the problem.  For 
example, the CMD file would echo a "mkdir" command to the stdout and the 
"mkdir" would complain to stderr that the directory already existed.  
However, the stderr line appeared before the stdout line !

Second, I used the "output" attribute on a "<java>" task that invoked the 
Xalan XSLT processor.  The output was some Java code.  However, a "^M" was 
showing up in the middle of a line: in the middle of a Java identifier, 
worse yet !  I found if I changed the invocation so that I used the "-out" 
command line argument for Xalan and stopped using the "output" attribute of 
<java>, the problem went away.  This makes me believe that the "^M" was 
coming from the invocation's stderr, and the stdout/stderr merging for the 
"output" attribute was in this case merging the stderr "^M" into the 
*MIDDLE* of a stdout line !

Not what I'd hoped for...

Anyway, anyone have any comments ?  Have other people run into such problems 

I realize that the problem of reading BOTH the stdout and stderr streams of 
a Java "Process" is not an easy thing to do correctly.  Frankly, I can't say 
with enough confidence that *I* know what "the right" approach is.  I've 
written code that uses separate threads, one for reading lines from a 
Process' stdout and another for reading its stderr lines.  With careful use 
of "synchronized", etc., they send the lines they get to a third thread's 
sequence-of-lines Vector...  "Works for me", but I'm not sure line-base 
reading is more "correct" than character-based...

Does anyone know of (say) an article or FAQ or paper that addresses the 
issue ?  I guess more importantly: can anyone say that the way Ant's <java> 
and <exec> tasks merge their streams in supporting the "output" attribute 
corresponds to some recommended or "standard" way of reading a Process' two 
output streams ?

My experience just makes me think Ant isn't doing the right thing, I 

Rich Wagner

The new MSN 8: advanced junk mail protection and 2 months FREE*

View raw message