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
| package test;
public class TestCmd {
public TestCmd() {
System.out.println("begin");
try {
Runtime r = Runtime.getRuntime();
System.out.println("r="+r);
String [] s={"cmd","/c","dir"};
Process p = r.exec(s);
System.out.println("p="+p);
p.getOutputStream().close();
// p.waitFor(); si cette ligne est omise, tout fonctionne bien;
// mais c'est pas propre!
}catch(Exception e) {
System.out.println("erreur d'execution " );
e.printStackTrace();
}
System.out.println("fin");
}
public static void main(String[] args) {
new TestCmd();
}
} |
Partager