Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate command promt input

Status
Not open for further replies.

bobrivers2003

Technical User
Oct 28, 2005
96
GB
Hi,

I have created a class that executes an ant script. If the ant does not require an input it works fine. However, sometimes the script will ask a qustion from which the user must type either y or n followed by return.

When my class runs this file it hangs when it gets to this bit.

I understand that I may have to use something along the line of bufferedReader. My question:

If I use
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

and

br.readLine();

it requires the user to enter something in. I want java to automatically type y or n followed by return. Does any body know the area that I need to be looking in to solve this issue?

Any help would be greatly appreciated.

Many Thanks
 
Not sure if you can simulate someone pressing a key.

Obvious answer is you have coded in the readLine() - then don't.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
The java.awt.Robot class is designed to automate keyboard and mouse input. I've never used it, though. It may need to be used on a separate thread to the Event Dispatch thread of the gui system.

Have a look. If you do try it and get it working, post you experience back here. I for one would be interested to know if Robot works as advertised. I've recommended its use a couple of times before, but have never had chance to try it for myself.

Tim
 
I don't think the java.awt.Robot class is terribly hard to work with actually, used it some for a project a while back. Wasn't too hard...
 
duddev said:
I don't think the java.awt.Robot class is terribly hard to work with actually

Excellent. Then maybe bobrivers2003 could make productive use of it. Maybe he'll even respond at some point to the thread he's started.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top