|
@@ -3,6 +3,8 @@ package api.common.util;
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
+import java.io.BufferedInputStream;
|
|
|
|
+import java.io.InputStream;
|
|
import java.net.InetAddress;
|
|
import java.net.InetAddress;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -12,8 +14,20 @@ import java.net.InetAddress;
|
|
public class OsUtil {
|
|
public class OsUtil {
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
public static void exec(String command) {
|
|
public static void exec(String command) {
|
|
|
|
+ String result;
|
|
log.info("执行命令:{}", command);
|
|
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
|
|
@SneakyThrows
|