1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public static void main(String[] args) {
Runtime runtime = Runtime.getRuntime();
String[] cmdArray = {"cmd.exe","/c","dir"}; //etc
Process process;
try {
String line;
process = runtime.exec(cmdArray);
InputStream stdout = process.getInputStream();
BufferedReader reader = new BufferedReader (new InputStreamReader(stdout));
while ((line = reader.readLine ()) != null) {
System.out.println ("Stdout: " + line);
}
process.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
Partager