• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Execute an application from java and interact with it.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interacting with GUIs is even more tricky since GUIs are usually not threadȁsafe.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic