From be6edcf2ae26fa8595ad6b25509dcfebd6f3e111 Mon Sep 17 00:00:00 2001 From: zeaslity Date: Sat, 25 Feb 2023 18:43:33 +0800 Subject: [PATCH] [agent][executor]- bug - 2 --- .../io/wdd/agent/executor/CommandExecutor.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java b/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java index b4de18c..4fdd0d7 100644 --- a/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java +++ b/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java @@ -132,6 +132,7 @@ public class CommandExecutor { // get the command result must also be a timeout smaller than the process int waitFor = process.waitFor(); + // get the process result if (ObjectUtils.isNotEmpty(waitFor) && ObjectUtils.isNotEmpty(process.info())) { @@ -139,15 +140,15 @@ public class CommandExecutor { countDownLatch.countDown(); } + // 设置 命令执行退出返回值 + processResult = process.exitValue(); + log.debug( "current shell command {} result is {}", processBuilder.command(), processResult ); - // 设置 命令执行退出返回值 - processResult = process.exitValue(); - } catch (IOException | InterruptedException e) { log.error( "Shell command error ! {} + {}", @@ -200,10 +201,16 @@ public class CommandExecutor { // 命令没有正确的处理完成,需要手动关停程序 - // 只有当该进程还存活,执行关闭操作 + // 只有当该进程还存活,执行关闭操作, 没有返回结果的命令如 ping baidu.com 只有在线程关闭之后才可以有结果s if (process.isAlive()) { // shutdown the process - log.debug("开始销毁命令执行进程!"); + log.debug( + "开始销毁命令[ {} ]执行进程!", + process + .info() + .commandLine() + .get() + ); process.destroy(); } }