【发布时间】:2021-12-09 12:21:21
【问题描述】:
我正在使用 Java 程序中的 DefaultExecutor 和 CommandLine 执行 shell 脚本。
为了成功执行接收 0 退出值
但如果失败或 任何其他退出代码(如 127,128,255 等)来自 shell 脚本,则不会收到相应的退出代码,而是获得 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);
}
任何想法如何处理退出代码以执行特定的自定义操作?
【问题讨论】:
标签: java shell command-line exit-code executor