• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interaction with Command Line program

 
Richard Cumbers
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey people
I have a command line program that I would like to interact with my java program. It takes in a string on the command line and generates a response from that. I need this to happen in real time and so I guess I need threads aswell. How would I get the response from the same program that I gave the input too?
Cheers
Cumbers
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.Runtime.exec() returns a java.lang.Process instance. One can obtain the input, output and error streams from that object and use them appropriately.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if my little CmdServer project gives you any ideas. I probably went overboard on all the threaded readers for the stdout and errout. I once used a language (EASEL) that used this technique as their standard integration API. For example, they provided SQL access as a separate C module that took SQL in stdin and returned CSV results to stdout. Kinda cool.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!