Bug 41024

Summary: Problem with Input task
Product: Ant Reporter: Ronan Mulvaney <rmulvaney>
Component: Core tasksAssignee: Ant Notifications List <notifications>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P2    
Version: 1.7.0   
Target Milestone: ---   
Hardware: Other   
OS: other   

Description Ronan Mulvaney 2006-11-23 04:34:03 UTC
I am having a problem with the input task where it doesn't seem to validate the 
arguments being passed and just sits there awaiting input.
I have narrowed this down to a small test case that shows when a forked java 
process is called before the input task it does this...! Without the java task 
there or being forked it behaves fine.

The build.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<project name="builds_scripts" default="compile">
  <target name="compile">
    <javac
      srcdir="C:/Temp"
      destdir="C:/Temp"
      includes="TestCase.java"
    />
    <java
      classname="TestCase"
      classpath="C:/Temp"
      fork="yes"
    >
    </java>
    <input
     message="Input?"
     validargs="y,n"
     addproperty="do.tag"
    />    
  </target>
</project>

The TestCase.java looks like:

public class TestCase{
  public static void main(final String[] arguments) {
    System.out.println("Testing");
  }
}

Cheers.
Comment 1 Steve Loughran 2006-11-23 05:00:42 UTC
What's probably happening is that the input is being routed to the forked java
program, which is ignoring it. 

If you dont want this behaviour, add inputstring="" to the <java> task.

Now, the interesting question is why is this happening after the forked java
program has terminated. 
Comment 2 Ronan Mulvaney 2006-11-24 01:06:33 UTC
I can confirm that works around the issue.
That said, we have a fairly large number of forked <java> tasks in our scripts 
and others not under our control that we import to make this change in.
How likely would it be to see a fix for this issue in the final release?
Comment 3 Richard Ward 2007-07-31 06:49:16 UTC
I've encountered similar behaviour in version 1.6.5 and 1.7.0 (1.6.2 is ok). It
seems the input has to pass through the hierarchy of forked java calls before
the input is accepted. So 

    <target name="test-forked-inputs">
        <input>Not called java so assuming 1 return to continue.</input>
        <echo>Calling java </echo>
        <java classname="Hello" classpath="." fork="true"/>
        <echo>Calling java for the second time</echo>
        <java classname="Hello" classpath="." fork="true"/>
        <echo>Calling java for the third time</echo>
        <java classname="Hello" classpath="." fork="true"/>
        <echo>Calling java for the fourth time</echo>
        <java classname="Hello" classpath="." fork="true"/>
        <input>Called java 4 times since last input, so assuming 5 returns to
continue (4 for each forked java, plus 1 for the input).</input>
    </target>

requires the return key to be pressed once initially, then 5 times (as the
message says, 4 times for the number of forked java instances, plus one for the
input task itself). Doing either of a) removing the forked attribute or b)
setting inputstring="" in the java call gets around the problem.

IMHO the problem is as likely to be in the java task as in the input task. Ant
1.6.3 saw a fix to the java task [Programs run with <java fork="true"> can now
accept standard input from the Ant console. (Programs run with <java
fork="false"> could already do so.) Bugzilla 24918.]
Comment 4 Stefan Bodewig 2008-08-21 05:29:15 UTC

*** This bug has been marked as a duplicate of bug 34461 ***