mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-11 03:13:51 +00:00
chore[command]: reduce the volume of logs for process command
This commit is contained in:
1 parent
2d31c2aa34
commit
1030dd354b
1 file changed
+7
-11
@@ -296,20 +296,20 @@ public abstract class OSUtils {
|
||||
.directory(wd)
|
||||
.start();
|
||||
|
||||
var out = new StringBuilder();
|
||||
var err = new StringBuilder();
|
||||
var stdout = new StringBuilder();
|
||||
var stderr = new StringBuilder();
|
||||
|
||||
// 异步读取输出,避免缓冲区阻塞
|
||||
executors.submit(ThreadUtils.safeRunnable(() -> {
|
||||
try {
|
||||
out.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getInputStream())));
|
||||
stdout.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getInputStream())));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}));
|
||||
executors.submit(ThreadUtils.safeRunnable(() -> {
|
||||
try {
|
||||
err.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getErrorStream())));
|
||||
stderr.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getErrorStream())));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -326,14 +326,10 @@ public abstract class OSUtils {
|
||||
|
||||
// 获取线程的退出值,0代表正常退出,非0代表异常中止
|
||||
int exitValue = process.exitValue();
|
||||
if (exitValue != 0) {
|
||||
logger.error("doExecCommand error executing command exitValue:[{}] result:[{}] err:[{}]", exitValue, err, err);
|
||||
if (exitValue != 0 || !stderr.isEmpty()) {
|
||||
logger.error("doExecCommand error executing command exitValue:[{}] stdout:[{}] stderr:[{}]", exitValue, stdout, stderr);
|
||||
}
|
||||
|
||||
if (!err.isEmpty()) {
|
||||
logger.error("doExecCommand error executing command err:[{}]", err);
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
return stdout.toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user