• 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

Shell script from a java application

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My requirement is as follows:
There is a java desktop application which runs a shell script. The shell script does an ssh to connect to a remote server and does some processing. The output of the shell script will be shown in the java application.

I started out with the following code but the program is getting hung. Any pointers regarding where I am going wrong will be highly appreciated.



 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can see three problem -

1) You need to send an end-of-line (a \n) after the command and to close() the stdin stream.
2) You need to process stderr because if the stderr buffer fills before the process has completed then you will get a deadlock. This should be done in a separate thread.
3) You need to process stdout in a separate thread since again it can cause deadlock if it's buffer becomes full.

You would do well to read the 4 sections of the traps article and implement ALL the recommendations.
 
Sayantan Auddy
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot James
reply
    Bookmark Topic Watch Topic
  • New Topic