Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Runtime interfaces

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Intermediate forum...
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic