Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

capturing windows app's output

 
Servin Park
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a command prompt windows application (DOS like, call it "the-app" from this point on) that is not intuitive to use. So I built a java app that offers GUI screen to take user input and in the background converts information to proper commands that the-app undersands. And then using JNI, sends those commands to the-app. So far so good, my java app works and the-app responds without any problem. My problem is though, somehow I have to retrieve a couple reponses from the-app. In other words, at the end of process the-app prints confirmation number on its screen and I need to copy the confirmation number and paste it to my java app. Does anyone has any idea how I could do this? Or is it possible at all? Thanks in advance for your help.
 
Omar IRAQI
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Servin,
I assume that you are using java.lang.Runtime.exec() to run "the_app". If this is actually the case, you can do the following :
Process the_appProcess = thisRuntime.exec("pathTothe_app + parameters");
InputStream ins = the_appProcess.getInputStream();
Once you have the ins handle, you can parse the stream and retrieve the needed data.
I Hope this would help.
 
Servin Park
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Omar,
Thank you so much for your pointer. I would never have found Process class on my own. By the way, I noticed Process.getOutputStream() method. Does it mean my java app can even write to the-app?
 
Omar IRAQI
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Servin, definitly.
Take care
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic