mbodjsystem
1 nov. 2007 à 13:01
Bonjour, voici comment lancer un programme exécutable sous java.
//passage par argument de la commande à lancer
public void StartCommand(String command) {
try {
//creation du processus
Process p = Runtime.getRuntime().exec(command);
InputStream in = p.getInputStream();
//on récupère le flux de sortie du programme
StringBuilder build = new StringBuilder();
char c = (char) in.read();
while (c != (char) -1) {
build.append(c);
c = (char) in.read();
}
String response = build.toString();
//on l'affiche
System.out.println(response);
}
catch (Exception e) {
System.out.println("\n" + command + ": commande inconnu ");
}
}
www.mbodjsystem.com