Exécuter plusieurs commandes bat
Bonjour, je cherche a redémarrer automatiquement mon serveur J2EE.
J'arrive bien à l'arrêter, mais pas à le démarrer. (Le message "démarrage de jonas" apparait et puis...pouf j'attends indéfiniment.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
public class Main {
public static void main(String[] args) {
try {
int c;
String fileName = "test.txt";
String strToSearch = "documenta";
String commande = "", resultat = "";
Process proc;
while (true) {
resultat = "";
// on lance la commande findstr pour chercher la chaine "Erreur 500"
commande = "findstr /C:" + strToSearch + " E:\\" + fileName;
proc = Runtime.getRuntime().exec(commande);
// récupère le résultat de la commande
InputStream in = proc.getInputStream();
while ((c = in.read()) != -1) {
resultat += ((char) c);
}
in.close();
proc.destroy();
if (resultat.length() == 0) {
// on a trouvé une erreur 500 il faut donc redémarrer le serveur
stopJOnAS();
startJOnAS();
}
}
} catch (IOException e) {
System.out.println(e.toString());
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
// arrête le serveur
private static void stopJOnAS() {
System.out.println("Arrêt de JonAS");
String cmd = "E:\\JOnAS Stop.bat";
Process proc;
try {
proc = Runtime.getRuntime().exec(cmd);
proc.waitFor();
proc.destroy();
System.out.println("JOnAS arrêté !");
} catch (IOException e) {
System.out.println(e.toString());
} catch (InterruptedException e) {
System.out.println(e.toString());
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
// démarre le serveur
private static void startJOnAS() {
System.out.println("Démarrage de JonAS");
String cmd = "E:\\JOnAS Start.bat";
Process proc;
try {
proc = Runtime.getRuntime().exec(cmd);
proc.waitFor();
proc.destroy();
System.out.println("JOnAS démarré !");
} catch (IOException e) {
System.out.println(e.toString());
} catch (InterruptedException e) {
System.out.println(e.toString());
}
}
} |
Sauriez-vous m'aider ?
Merci à vous !