Browse Source

将项目运行节点拆分成GPU节点和CPU节点

LingxinMeng 2 years ago
parent
commit
c17ea93ad7
1 changed files with 15 additions and 1 deletions
  1. 15 1
      api-common/src/main/java/api/common/util/OsUtil.java

+ 15 - 1
api-common/src/main/java/api/common/util/OsUtil.java

@@ -3,6 +3,8 @@ package api.common.util;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 
+import java.io.BufferedInputStream;
+import java.io.InputStream;
 import java.net.InetAddress;
 
 /**
@@ -12,8 +14,20 @@ import java.net.InetAddress;
 public class OsUtil {
     @SneakyThrows
     public static void exec(String command) {
+        String result;
         log.info("执行命令:{}", command);
-        Runtime.getRuntime().exec(command);
+        Runtime run = Runtime.getRuntime();
+        Process process = run.exec(command);
+        InputStream in = new BufferedInputStream(process.getInputStream());
+        StringBuilder out = new StringBuilder();
+        byte[] b = new byte[8192];
+        for (int n; (n = in.read(b)) != -1; ) {
+            out.append(new String(b, 0, n));
+        }
+        in.close();
+        process.destroy();
+        result = out.toString();
+        log.info("执行结果为:{}", result);
     }
 
     @SneakyThrows