示例程序如下:
import java.io.IOException;
import java.io.InputStream;
public class RunDOS {
public static void main(String[] args) {
final String dosCommand = "ipconfig /all";
try {
final Process process = Runtime.getRuntime().exec(
dosCommand);
final InputStream in = process.getInputStream();
int ch;
while ((ch = in.read()) != -1) {
System.out.print((char) ch);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}