• Post Reply Bookmark Topic Watch Topic
  • New Topic

Execute an application from java and interact with it.  RSS feed

 
Abhiram ka
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I trying to execute an application using java code "Process p = Runtime.getRuntime().exec(cmd);" but this does'nt allow me to interact with this application. Is there any way , we can read the output of executed application and again pass on some input parameters to that application based on it output in the first step . Please let me know if something is not clear.

Thanks,
A
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhiram,
Welcome to CodeRanch!

This JavaWorld article doesn't answer your question,b ut it is a great read about Runtime.exec so I recommend it anyway. I don't think you can do what you are asking. Runtime.exec isn't meant to be interactive. It's meant to kick off a process and get output back.

Did you write the Java program that you want to call? Do you know who did?
 
Tony Docherty
Bartender
Posts: 3264
81
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Absolutely definitely read the article Jeanne linked to. It is a must read for anyone using Runtime.exec.

To answer your question it is possible to have a simple interaction with an application you have launched through Runitme.exec (or better still via java.lang.ProcessBuilder) provided that the interaction can be achieved via input/output streams ie the application must take input from and write its output to the command line.
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the Process class. It is meant to interact with command line applications only not with GUI ones.

Interacting with GUI ones is quite more tricky and usually involves a frame buffer. I have never done this with java.
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interacting with GUIs is even more tricky since GUIs are usually not threadȁsafe.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!