Ajout de l'héritage des entrées/sorties dans CommandExecutor + Ajout du test 11
This commit is contained in:
parent
2d00f55fbe
commit
623f737ccc
@ -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();
|
||||
|
1
tests/C/test-11-error-in-code/README.md
Normal file
1
tests/C/test-11-error-in-code/README.md
Normal file
@ -0,0 +1 @@
|
||||
Quand il y a une erreur dans le code, ça affiche l'erreur + stop le programme exactement comme make.
|
7
tests/C/test-11-error-in-code/bake/Bakefile
Normal file
7
tests/C/test-11-error-in-code/bake/Bakefile
Normal file
@ -0,0 +1,7 @@
|
||||
all: main
|
||||
|
||||
main: main.c
|
||||
gcc -o main main.c
|
||||
|
||||
clean:
|
||||
rm -f main
|
15
tests/C/test-11-error-in-code/bake/main.c
Normal file
15
tests/C/test-11-error-in-code/bake/main.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
printf("Normalement, ce code ne fonctionne par car j'ai été stupide...\n");
|
||||
|
||||
// La fonction qui suit n'existe pas donc le programme ne peut pas compiler et renvoie une erreur.
|
||||
fonctionQuiNexistePas();
|
||||
|
||||
// La division par zéro est impossible, le programme renvoie un warning.
|
||||
int a = 15;
|
||||
a = a/0;
|
||||
|
||||
return 0;
|
||||
}
|
7
tests/C/test-11-error-in-code/make/Makefile
Normal file
7
tests/C/test-11-error-in-code/make/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
all: main
|
||||
|
||||
main: main.c
|
||||
gcc -o main main.c
|
||||
|
||||
clean:
|
||||
rm -f main
|
15
tests/C/test-11-error-in-code/make/main.c
Normal file
15
tests/C/test-11-error-in-code/make/main.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
printf("Normalement, ce code ne fonctionne par car j'ai été stupide...\n");
|
||||
|
||||
// La fonction qui suit n'existe pas donc le programme ne peut pas compiler et renvoie une erreur.
|
||||
fonctionQuiNexistePas();
|
||||
|
||||
// La division par zéro est impossible, le programme renvoie un warning.
|
||||
int a = 15;
|
||||
a = a/0;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user