mirror of
https://github.com/davidalves04/Trabalho-Pratico-SD.git
synced 2025-12-08 12:33:31 +00:00
feat: Dynamically set simulation log file path using OS temporary directory and remove isSimulationRunning method.
This commit is contained in:
@@ -95,18 +95,24 @@ public class SimulationProcessManager {
|
|||||||
builder = new ProcessBuilder(javaBin, "-cp", classpath, className);
|
builder = new ProcessBuilder(javaBin, "-cp", classpath, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is a linux thing - not sure about windows
|
// get the OS temp folder
|
||||||
|
// Linux: /tmp/
|
||||||
|
// Windows: %AppData%\Local\Temp\
|
||||||
|
String tempDir = System.getProperty("java.io.tmpdir");
|
||||||
|
|
||||||
String logName = className.substring(className.lastIndexOf('.') + 1) + (arg != null ? "-" + arg : "") + ".log";
|
String logName = className.substring(className.lastIndexOf('.') + 1) + (arg != null ? "-" + arg : "") + ".log";
|
||||||
File logFile = new File("/tmp/" + logName);
|
|
||||||
|
// use the (File parent, String child) constructor to handle slash/backslash
|
||||||
|
// automatically
|
||||||
|
File logFile = new File(tempDir, logName);
|
||||||
|
|
||||||
builder.redirectOutput(logFile);
|
builder.redirectOutput(logFile);
|
||||||
builder.redirectError(logFile);
|
builder.redirectError(logFile);
|
||||||
|
|
||||||
Process process = builder.start();
|
Process process = builder.start();
|
||||||
runningProcesses.add(process);
|
runningProcesses.add(process);
|
||||||
System.out.println("Started " + className + (arg != null ? " " + arg : ""));
|
System.out.println("Started " + className + (arg != null ? " " + arg : ""));
|
||||||
}
|
// print where the logs are actually going
|
||||||
|
System.out.println("Logs redirected to: " + logFile.getAbsolutePath());
|
||||||
public boolean isSimulationRunning() {
|
|
||||||
return !runningProcesses.isEmpty() && runningProcesses.stream().anyMatch(Process::isAlive);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user