• Post Reply Bookmark Topic Watch Topic
  • New Topic

invoking linux shell commands via java vs copying sh file  RSS feed

 
SaurabhRc Jain
Greenhorn
Posts: 12
Java Linux
  • Mark post as helpful
  • send pies
  • 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
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!