bug 处理

This commit is contained in:
朱春云 2025-09-04 16:09:03 +08:00
parent 70d3ab00f2
commit e6eadcb074

View File

@ -44,8 +44,23 @@ public class ShellUtil {
Process process = processBuilder.start(); Process process = processBuilder.start();
// 复用原有的业务逻辑处理 // 处理标准输出
resInfo = processScriptOutput(process, patientScript, resInfo); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String outputLine;
System.out.println("=== Standard Output ===");
while ((outputLine = reader.readLine()) != null) {
System.out.println(outputLine);
// 将输出传递给业务逻辑处理方法
processSingleOutputLine(outputLine, patientScript, resInfo);
}
// 处理错误输出
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String errorLine;
System.err.println("=== Error Output ===");
while ((errorLine = errorReader.readLine()) != null) {
System.err.println(errorLine);
}
// 等待命令执行完成 // 等待命令执行完成
int exitCode = process.waitFor(); int exitCode = process.waitFor();
@ -62,18 +77,13 @@ public class ShellUtil {
} }
/** /**
* 处理脚本输出复用原有的业务逻辑 * 处理单行输出复用原有的业务逻辑
* @param process 进程对象 * @param line 输出行
* @param patientScript 患者脚本对象 * @param patientScript 患者脚本对象
* @param resInfo 结果信息 * @param resInfo 结果信息
* @return 更新后的结果信息
* @throws Exception 处理异常 * @throws Exception 处理异常
*/ */
private static String processScriptOutput(Process process, PatientScript patientScript, String resInfo) throws Exception { private static void processSingleOutputLine(String line, PatientScript patientScript, String resInfo) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
if (line.contains("\"tr\"") && line.contains("{") && line.contains("}")) { if (line.contains("\"tr\"") && line.contains("{") && line.contains("}")) {
System.out.println(line + "tr11111111************************************************************"); System.out.println(line + "tr11111111************************************************************");
JSONObject jsonObject = JSONObject.parseObject(line); JSONObject jsonObject = JSONObject.parseObject(line);
@ -145,8 +155,6 @@ public class ShellUtil {
throw new Exception("生成异常"); throw new Exception("生成异常");
} }
} }
return resInfo;
}
public static void execCmd(String cmd) throws IOException { public static void execCmd(String cmd) throws IOException {
Runtime run = Runtime.getRuntime(); Runtime run = Runtime.getRuntime();
@ -190,4 +198,5 @@ public class ShellUtil {
// ... existing code ... // ... existing code ...
} }