I am executing shell script using DefaultExecutor & CommandLine from Java Program.
For successful execution receiving 0 exit value
but in case of failure or any other exit code (like 127,128,255 etc.) from shell script, not receiving respective exit code instead getting IOException.
int iExitValue = 1;
CommandLine cmd = CommandLine.parse("sh /Users/DpakG/scripts/do_Database_Operations.sh");
DefaultExecutor oDefaultExecutor = new DefaultExecutor();
oDefaultExecutor.setExitValue(0);
try {
iExitValue = oDefaultExecutor.execute(cmd);
log.info("Script Exit Code: " + iExitValue);
} catch (IOException e) {
log.error("IOException occurred: ", e);
}
Any Idea How to handle exit code to perform specific custom action?