• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

invoking linux shell commands via java vs copying sh file

 
Greenhorn
Posts: 17
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

We need to execute 3-4 shell commands from a Java application.
We are able to do it successfully using jcraft jsch library.
Now is invoking each command separately from Java code is better approach than copying a shell file to the target machine & executing as single command from java?
Target machine is over network, so network IO is one aspect.
is there any other difference from design perspective?


Thanks,
Saurabh
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect that this comes down to what happens if one or more of the scripts fails and some form of rollback is required. In the absence of the need for rollback my preference is to invoke the scripts individually from within Java so that the stdout and stderr outputs can be separated without contortions.

P.S. You need to purge the stdout and stderr streams available from the channel or you risk a deadlock. What you do with the content is up to you but I my preference is to make it in some way viewable to help in the debug process.
 
Sheriff
Posts: 17783
306
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are other solutions for this kind of problem besides the one chosen. Things I would ask before committing to that solution are:
1. How often do we need to run these commands?
2. How much flexibility do we need in running them? What kind of parameters are involved?
3. What kind of security concerns must be considered? What's the threat profile?
4. How is the output of the commands used? What about the results, who uses those and how do they get them?
5. What considerations do we have to make regarding maintenance and deployment? Version control?
reply
    Bookmark Topic Watch Topic
  • New Topic