Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Execution d'une appli a partir du code java

2 réponses
Avatar
Yohan Colmant
Bonjour,
j'essaye de lancer l'execution d'une appli depuis mon code java, mais ca
plante, meme un petit "dir" tout simple, quelqu'un aurait-il la solution ?

Mon code:
Runtime runtime = Runtime.getRuntime();
String exec[] = new String[1];
exec[0] = "dir";
String env[] = new String[0];
File f = new File(".\\annuaire");
try {
runtime.exec(exec);
}
catch(Exception e) {
e.printStackTrace();
}

l'erreur:
java.io.IOException: CreateProcess: dir error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:63)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at java.lang.Runtime.exec(Runtime.java:491)
at java.lang.Runtime.exec(Runtime.java:457)

Merci,
Yohan

2 réponses

Avatar
Pierre Salagnac
je ne sais pas ce qu'il faut utiliser à la place, mais 'dir' n'est pas une
application mais une commande à l'os
Avatar
Philippe
Bonjour

Runtime runtime = Runtime.getRuntime();
String exec[] = new String[1];
exec[0] = "dir";


Essaies en créant une nouvelle commande Dos :
exec[0]= "cmd /c dir";

String env[] = new String[0];
File f = new File(".annuaire");
try {
runtime.exec(exec);
}
catch(Exception e) {
e.printStackTrace();
}