Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running a java task that has interactive console input

 
steve claflin
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
steve claflin
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic