This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime.getRuntime() execute script which asks for input from user.  RSS feed

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to run script on Unix which after execution asks for input from the user, this is done 4-5 times. After every input the user presses the enter key.

How do I implement this using Runtime get Runtime() in my Java application?
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, you should get familiar with how Runtime.exec deals with the input and output of the processes it starts. This article is a very good start.

Then you'll need to think about reading and parsing the input stream. How do you find out when the script is done sending (probably at a line end), and what do you need to send as response?

Does the Java code know how to respond to the script, or must it show the script output to the user, and ask for input from him?
[ February 06, 2008: Message edited by: Ulf Dittmer ]
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Whatever the user keystrokes shows up in the variable input.
 
Do not set lab on fire. Or this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!