You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Michael Sobremonte <mi...@redshift.co.za> on 2008/12/15 14:34:51 UTC

"Failed to read input from Console" Error invoking ant from java class

Hi

I am trying to call an ant target requiring input from within a java class.

My build file is menu-based so it jumps from menu to menu depending on
the input.

The problem is as soon as input is entered in INPUT MENU 1,
The next menu will fail to read input.

eg:

# INPUT MENU 1:
<input message="Select an option:"  validargs="1,2,X"
addproperty="main.option"/>

# INPUT MENU 2:
<input message="Select an option:" validargs="Y,N"
addproperty="abort.option"/>

In the above example, as soon as "X" is entered for INPUT MENU 1 and the
INPUT MENU 2 message is displayed,
ant will fail with a "Failed to read input from Console." message
pointing to the the INPUT MENU 2 line.

My AntInvoker class is similiar to the example in:
http://www.ibm.com/developerworks/websphere/library/techarticles/0502_gawor/0502_gawor.html

Thanks for any input.

Cheers,
Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: "Failed to read input from Console" Error invoking ant from java class

Posted by Michael Sobremonte <mi...@redshift.co.za>.
Hi

Thanks for the input Mark.

After some researching I found the same issue logged as a bug here:
https://issues.apache.org/bugzilla/show_bug.cgi?id=42544

Quick Solution:

I used the DefaultInputHandler from apache-ant-1.6.5

http://ant.apache.org/manual/CoreTasks/input.html
http://ant.apache.org/manual/inputhandler.html#defaulthandler

Cheers,
Michael

-------- Original Message  --------
Subject: Re: "Failed to read input from Console" Error invoking ant from
java class
From: Mark Salter <ma...@talktalk.net>
To: Ant Users List <us...@ant.apache.org>
Date: mon, 15 dec 2008 21:28:38 +0000

> Michael Sobremonte wrote:
>> I am trying to call an ant target requiring input from within a java class.
> Why do you want to do it this way?
> 
> Why not use ant natively or System.in directly from java *before*
> invoking ant to react to the options selected?
> 
> 
>> # INPUT MENU 1:
>> <input message="Select an option:"  validargs="1,2,X"
>> addproperty="main.option"/>
>>
>> # INPUT MENU 2:
>> <input message="Select an option:" validargs="Y,N"
>> addproperty="abort.option"/>
> 
> It works as designed when running ant with a build file of :-
> 
> <project name="inputtest" default="build">
>         <target name="build">
> 	   <input message="Select an option:"  validargs="1,2,X"
> 	      addproperty="main.option"/>
> 
> 	   <input message="Select an option:" validargs="Y,N"
> 	      addproperty="abort.option"/>
>         </target>
> 
> </project>
> 
> To get this to work in code, you are going to have to copy what ant does
> for *each* input task.
> 
>> In the above example, as soon as "X" is entered for INPUT MENU 1 and the
>> INPUT MENU 2 message is displayed,
>> ant will fail with a "Failed to read input from Console." message
>> pointing to the the INPUT MENU 2 line.
> 
> I imagine is is related to how you are passing in a *single* "System.in"
> in on your ant invocation, which successive input tasks are trying to
> reuse and fighting over.
> 
> You are using ant in a non standard way, and are going to have to do
> more investigation yourself to see what ant does with console input to
> make it work, or adjust your approach.
> 
> The ant input task is not broken, I think you are breaking it by
> invoking it in the way you are which appears to be in conflict with how
> it was developed.
> 
>> My AntInvoker class is similiar to the example in:
>> http://www.ibm.com/developerworks/websphere/library/techarticles/0502_gawor/0502_gawor.html
> This example only deals with output, not input which are quite different
> in their mechanisms.
> 
> Good luck.
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: "Failed to read input from Console" Error invoking ant from java class

Posted by Mark Salter <ma...@talktalk.net>.
Michael Sobremonte wrote:
> 
> I am trying to call an ant target requiring input from within a java class.
Why do you want to do it this way?

Why not use ant natively or System.in directly from java *before*
invoking ant to react to the options selected?


> # INPUT MENU 1:
> <input message="Select an option:"  validargs="1,2,X"
> addproperty="main.option"/>
> 
> # INPUT MENU 2:
> <input message="Select an option:" validargs="Y,N"
> addproperty="abort.option"/>

It works as designed when running ant with a build file of :-

<project name="inputtest" default="build">
        <target name="build">
	   <input message="Select an option:"  validargs="1,2,X"
	      addproperty="main.option"/>

	   <input message="Select an option:" validargs="Y,N"
	      addproperty="abort.option"/>
        </target>

</project>

To get this to work in code, you are going to have to copy what ant does
for *each* input task.

> 
> In the above example, as soon as "X" is entered for INPUT MENU 1 and the
> INPUT MENU 2 message is displayed,
> ant will fail with a "Failed to read input from Console." message
> pointing to the the INPUT MENU 2 line.

I imagine is is related to how you are passing in a *single* "System.in"
in on your ant invocation, which successive input tasks are trying to
reuse and fighting over.

You are using ant in a non standard way, and are going to have to do
more investigation yourself to see what ant does with console input to
make it work, or adjust your approach.

The ant input task is not broken, I think you are breaking it by
invoking it in the way you are which appears to be in conflict with how
it was developed.

> 
> My AntInvoker class is similiar to the example in:
> http://www.ibm.com/developerworks/websphere/library/techarticles/0502_gawor/0502_gawor.html
This example only deals with output, not input which are quite different
in their mechanisms.

Good luck.

-- 
Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org