• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to pass input to java program using ant ?

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have successfully invoked my java console application using ant but i m not sure how i can give input to my java console application i have develop this code

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what specific problem are you having? I see code that looks like it will read all the output of the ant it invokes and print that out to the console, and that does not send any input to that program via the console.

So, the first question is, how do you wish to provide this input? If the and demo expects it as a command line arg, then you just need to modify what you exec() appropriately. If the and demo expects is to come from the console via its System.in, then, just as you're currently proxying its System.out to your console, you need to proxy from your console to its System.in.

This article may help.
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:So, what specific problem are you having? I see code that looks like it will read all the output of the ant it invokes and print that out to the console, and that does not send any input to that program via the console.

So, the first question is, how do you wish to provide this input? If the and demo expects it as a command line arg, then you just need to modify what you exec() appropriately. If the and demo expects is to come from the console via its System.in, then, just as you're currently proxying its System.out to your console, you need to proxy from your console to its System.in.

This article may help.

from System.in I will be able to get the input from the netbeans console but how exactly i can transfer that to my program which i am invoking using ant.
my problem is the program reads the ant output , i guess till here its fine for you , but while writing the output to the console in the while loop it gets into infinite loop because it is expecting input from the user, but i m not able to come out of the while loop so that i can read the netbeans console and send it to my console app using printwriter, does you have any solution for that
and by the way i have already read the above said article from javaworld
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
naved momin wrote:
from System.in I will be able to get the input from the netbeans console but how exactly i can transfer that to my program which i am invoking using ant.


1) Read the article I linked.

2) You can only do it if that ant task is set up to accept input from the console in the first place. If it's not written to accept it, you can't force it. It will just not read any bytes you send to it.

my problem is the program reads the ant output , i guess till here its fine for you , but while writing the output to the console in the while loop it gets into infinite loop because it is expecting input from the user, but i m not able to come out of the while loop so that i can read the netbeans console


Read the article. It shows you how to set up separate threads for reading and writing.

and by the way i have already read the above said article from javaworld


Then you already have your answer, and I don't understand why you're positing here. I also don't understand why, having read that article, you failed to follow the model it provided.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic