generated from root/miduo_server
停服脚本日志输出修改
parent
aabe4cea6e
commit
91cbdeebf9
|
|
@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
|
@ -158,10 +159,8 @@ public class AutoServerManager {
|
|||
exec = Runtime.getRuntime().exec(command);
|
||||
|
||||
LOGGER.info("========================== 停服脚本执行结果开始 ===========================");
|
||||
new DealProcessSream(exec.getInputStream(),true).start();
|
||||
new DealProcessSream(exec.getErrorStream(),false).start();
|
||||
readProcessOutput(exec);
|
||||
LOGGER.info("=========================== 停服脚本执行结果结束 ==========================");
|
||||
|
||||
exec.waitFor();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -171,4 +170,38 @@ public class AutoServerManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印进程输出
|
||||
* @param process 进程
|
||||
*/
|
||||
private static void readProcessOutput(final Process process) {
|
||||
// 将进程的正常输出在 System.out 中打印,进程的错误输出在 System.err 中打印
|
||||
read(process.getInputStream(), System.out);
|
||||
read(process.getErrorStream(), System.err);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取输入流
|
||||
* @param inputStream
|
||||
* @param out
|
||||
*/
|
||||
private static void read(InputStream inputStream, PrintStream out) {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
out.println(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue