From 3c245b126e19386d2f321d2444d2213870e555ac Mon Sep 17 00:00:00 2001 From: zeaslity Date: Sat, 25 Feb 2023 18:55:49 +0800 Subject: [PATCH] [agent][executor]- bug - 2 --- .../wdd/agent/executor/CommandExecutor.java | 6 +++- .../executor/thread/CommandExecLogCache.java | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) 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 fc92d40..b6395ef 100644 --- a/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java +++ b/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java @@ -205,12 +205,16 @@ public class CommandExecutor { if (process.isAlive()) { // shutdown the process log.debug( - "开始销毁命令[ {} ]执行进程!", + "开始销毁命令 [ {} ] 执行进程!", process .info() .commandLine() .get() ); + + // 对线程进行debug + commandExecLogCache.debugProcessStreams(process); + process.destroy(); } } diff --git a/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java b/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java index 179c938..9b0e30f 100644 --- a/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java +++ b/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java @@ -104,6 +104,42 @@ public class CommandExecLogCache { return execLogCacheArrayList; } + /** + * 调试打印process哥各个 流 + * + * @param process + */ + public void debugProcessStreams(Process process) { + + log.debug( + "开始对一个process进行debug操作,process的信息为 {}, 执行时间为 {} , 执行结果为 {}", + process + .info() + .commandLine(), + process + .info() + .totalCpuDuration() + .get(), + process.exitValue() + ); + + log.debug("------------- inputStream -----------"); + new BufferedReader(new InputStreamReader(process.getInputStream())) + .lines() + .forEach( + System.out::println + ); + + + log.debug("------------- errorStream -----------"); + new BufferedReader(new InputStreamReader(process.getErrorStream())) + .lines() + .forEach( + System.out::println + ); + + } + /** * 实际执行命令缓存操作 *