Ajout de l'héritage des entrées/sorties dans CommandExecutor + Ajout du test 11

This commit is contained in:
2025-02-09 17:16:48 +01:00
parent 2d00f55fbe
commit 623f737ccc
6 changed files with 46 additions and 23 deletions

View File

@@ -37,31 +37,9 @@ public class CommandExecutor {
}
if (debug) System.out.println("Debug: Executing " + command);
ProcessBuilder pb = new ProcessBuilder("sh", "-c", command);
pb.inheritIO();
Process process = pb.start();
// Lire et afficher la sortie standard (stdout)
new Thread(() -> {
try (var reader = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}).start();
// Lire et afficher la sortie d'erreur (stderr)
new Thread(() -> {
try (var reader = new java.io.BufferedReader(new java.io.InputStreamReader(process.getErrorStream()))) {
String line;
while ((line = reader.readLine()) != null) {
System.err.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}).start();
// Attendre la fin du processus
int exitCode = process.waitFor();