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
@Test
public void test6() {
BufferedReader br = null;
Runtime rt = Runtime.getRuntime();
String cmdstr = "cmd.exe /c dir";
try {
Process process = rt.exec(cmdstr);
//输入执行结果
br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while((line = br.readLine())!=null){
System.out.println(line);
}
if (process != null) {
process.destroy();
process = null;
}
} catch (IOException e) {
e.printStackTrace();
}finally{
if (br != null) {
try {
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
* public Process exec(String command);
* public Process exec(String [] cmdArray);
* public Process exec(String command, String [] envp);
* public Process exec(String [] cmdArray, String [] envp);