Calling SH Unix command via Java


By far, one of the most simple, yet overlooked simple solution to batch and process executions.

Running an SH via Java isn’t really hard – there’s already an existing Object Utility for it, just need to call it correctly though. Java Code:

java_code_call_sh

the samplescript.sh is a custom script I created using nano. Basically, I pass alvin jay and reyes as parameters and get them by using $1,2 and 3.

nano_script

Console Output: I manage to get the output from the output stream object of the Process.

dir_sh

Download the source code here: