Bug 42544 - cannot have multiple input tasks with command line redirection
Summary: cannot have multiple input tasks with command line redirection
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.7.0
Hardware: Other other
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-29 17:13 UTC by David Thompson
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Thompson 2007-05-29 17:13:46 UTC
In 1.6.2 it used to be possible to invoke an ant script from an external java
program (or shell command) where input values were passed through command line
redirection with each value being terminated by a new line.

In 1.7.0 it appears this functionality has been broken since the
DefaultInputHandler has been modified to use a BufferedReader inside the
handleInput method. The problem with this is that in the first input task, the
bufferedreader will read up to the buffer size (8k), however the
DefaultInputHandler will only consume the first line of this. When the second
input task comes along it will not find anything (i guess maybe if you had very
large input you might find something).

We have a similar problem elsewhere in our code and we handled it by creating a
single static BufferedReader around System.in that was shared. This means that
line 1 can be read by one bit of code, line by the next and so on because they
are using a single BufferedReader.

In 1.6.2 the old code was using DataInputStream.readLine which is deprecated and
probably why the new code uses BufferedReader.

In order to solve my particular problem, I have written an extension of
BufferedReader which uses a single shared BufferReader around System.in. However
this is not a general purpose problem to the solution i think as the
InputHandler should handle the contract of working with the passed in stream.

One possible solution might be to implement a custom LineReader that does not
rely in BufferedReader.