• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime interfaces  RSS feed

 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently working on a project where I need my Java application to interface with a unix box. A really simple example might be: I want to run an application and then press 1 - to go to a certain menu in the system once the application has loaded:

Am i right in thinking that if I have something like this wont work:

Any ideas how I can get it to work easily? I have seen a little about the Java Native Interface stuff - but I dont really want to get bogged down by it.

Cheers
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Intermediate forum...
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you're right that won't work

If your Unix application is a console app that humans interact with via stdin and stdout you can get something going. The trick is to start the program with exec as you showed above, then get the input and output streams from the Process object returned by exec. Your program can read the application's stdout and errout and write to the application's sdtin. This can get a bit tricky because you may need to handle all this IO on separate threads. Dig into the doc on Process a bit, lemme know if that all makes sense.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and if it doesn't read from stdin/ stdout, you could use awt.Robot...
 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the problems with unix is that you dont need windows open to actually make the machine do things - so im not sure about the AWT-Robot - I've had a play with the stdin and out since you said - it's a bit of a nightmare. Im cheating at the moment and writing in perlscripts on the unix side and getting java to call them. I'd like to think Java had somekind of scripting equivilent to perl.

Cheers for the help - my quest will continue
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!