Comment exécuter un script.bat ?
Bonjour,
Je suis débutante en Java et j'aimerais pouvoir lancer un .bat à partir de mon programme.
J'ai essayé ce code mais il n'accepte pas run.exec
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 35 36
| import javax.imageio.IIOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Process;
public class cmde {
private static Process Process;
private static Object run;
/**
* @param args
*/
public static void main(String[] args) throws IIOException {
try {
Process pp = run.exec("c:\\Documents and Settings\\a497163\\Desktop\\MARWA\\bat et js\\exple.bat");
BufferedReader in = new BufferedReader(new InputStreamReader(pp.getErrorStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
int exitVal = pp.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
}
}
} |
L'erreur :
Citation:
The method exec(String) is undefined for the type Object
at cmde.main(cmde.java:24)
Quelqu'un saurait-il m'expliquer comment faire ?
Merci d'avance pour votre aide.