GeeCON Prague 2014*
The moose likes Ant, Maven and Other Build Tools and the fly likes Running a java task that has interactive console input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Running a java task that has interactive console input" Watch "Running a java task that has interactive console input" New topic
Author

Running a java task that has interactive console input

steve claflin
Ranch Hand

Joined: Dec 04, 2008
Posts: 54
When I run a java task that is a console app that prompts for inputs, I get no prompts, have to enter the data in what I hope is the correct sequence, and when the program ends it spits out a block of all the accumulated prompts. Is there a way around this?

I've tried the code below with fork="true" and fork="false" as well. (I thought it should be true, but it came to me this way.) I've also made a halfhearted attempt at using exec, which also did not work the way I want. And, I also tried to exec the command I can type into a console window to get a new command window instance (start), but apparently that isn't a real command represented by an exe or cmd file.

Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Do not use "fork" - it runs the Java app in another VM and that VM will not have access to your console and thus cannot get any input.

Without 'fork', you should be able to enter console text. But there is a slight gotcha - any prompts needs to use println (and not print) or else the prompts will not show up until after you enter the input!

You could also look into the 'input' attribute of the java task - it lets you provide canned responses in a text file.


JBoss In Action
steve claflin
Ranch Hand

Joined: Dec 04, 2008
Posts: 54
Thanks!!

In my application, we're testing, so I can indeed take the canned response route. But, I did try println as you suggested, and it worked as advertised.
 
GeeCON Prague 2014
 
subject: Running a java task that has interactive console input