Google

Monday, February 2, 2009

Command Execution


package practice;

import java.io.*;

public class CommandExecution {

public CommandExecution(String commandline) {
try {
String line;
Process p = Runtime.getRuntime().exec(commandline);
BufferedReader input =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
} catch (Exception err) {
err.printStackTrace();
}
}

public static void main(String argv[]) {
new CommandExecution("cmd /c dir");
}
}