From 8136a33646eba3352d1c105c0e988985de0d4153 Mon Sep 17 00:00:00 2001 From: 18616268358 <1440265357@qq.com> Date: Mon, 8 May 2023 18:46:05 +0800 Subject: [PATCH] =?UTF-8?q?#20230506=20=E6=AC=A3=E5=BD=B1=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=B9=B3=E5=8F=B0=E6=8B=8D=E7=85=A7=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/ProcessExecUtils.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 xymanager_common/src/main/java/com/shxy/xymanager_common/util/ProcessExecUtils.java diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/util/ProcessExecUtils.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/util/ProcessExecUtils.java new file mode 100644 index 0000000..c4c8418 --- /dev/null +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/util/ProcessExecUtils.java @@ -0,0 +1,52 @@ +package com.shxy.xymanager_common.util; + +import lombok.extern.slf4j.Slf4j; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.UUID; + +/** + * + * 上传文件 + * @author cy + */ +@Slf4j +public class ProcessExecUtils +{ + + /** + * 上传文件 + * + */ + public static Integer exec(String cmd) { + String line = ""; + StringBuffer sb = new StringBuffer(); + String result = ""; + Integer sendToCode = -1; + try { + Process ps = Runtime.getRuntime().exec(cmd); + log.info("传入cmd信息:{}",cmd); + BufferedReader reader = new BufferedReader(new InputStreamReader(ps.getInputStream())); + sendToCode = ps.waitFor(); + log.info("进程返回结果:{}",sendToCode); + while ((line = reader.readLine()) != null) { + sb.append(line).append("\n"); + } + if(StringUtils.isNotBlank(result)){ + log.info("查询最新结果:{}",result); + } + result = sb.toString(); + } catch (IOException e) { + log.error("IOException",e); + } catch (InterruptedException e) { + log.error("InterruptedException",e); + } + return sendToCode; + } + + + +}