bug 处理

This commit is contained in:
朱春云 2025-09-04 18:49:03 +08:00
parent 0ecebfc182
commit b9af177ad6

View File

@ -26,6 +26,14 @@ public class ShellUtil {
// 读取脚本文件内容
List<String> lines = Files.readAllLines(Paths.get(scriptPath));
// 设置工作目录为/data
File workingDir = new File("/data");
if (!workingDir.exists()) {
System.err.println("Warning: /data directory does not exist");
// 如果/data目录不存在则使用当前目录
workingDir = new File(".");
}
// 逐行执行命令跳过空行和注释行
for (String line : lines) {
// 去掉首尾空格
@ -37,10 +45,12 @@ public class ShellUtil {
}
System.out.println("Executing command: " + line);
System.out.println("Working directory: " + workingDir.getAbsolutePath());
// 执行单条命令
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("sh", "-c", line);
processBuilder.directory(workingDir); // 设置工作目录
Process process = processBuilder.start();
@ -76,6 +86,8 @@ public class ShellUtil {
return resInfo;
}
// ... existing code ...
/**
* 处理单行输出复用原有的业务逻辑
* @param line 输出行