package com.anxin.cmd.test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* @author: (le.qiao)
* @e-mail: qiaolevip@gmail.com
* @myblog: <a href="http://qiaolevip.iteye.com">http://qiaolevip.iteye.com</a>
* @date: 2012-10-8
*
*/
public class Command {
public static void main(String[] args) {
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("cmd /c dir"); // cmd /c calc
// Process pr = rt.exec("D:\\xunlei\\project.aspx");
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(), "GBK"));
String line = null;
while ((line = input.readLine()) != null) {
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code " + exitVal);
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
}
驱动器 D 中的卷没有标签。
卷的序列号是 D912-B944
D:\java\workspace\junit-test 的目录
2012-10-08 11:43 <DIR> .
2012-10-08 11:43 <DIR> ..
2012-10-08 11:43 295 .classpath
2012-10-08 11:43 386 .project
2012-10-08 11:43 <DIR> .settings
2012-10-08 11:45 <DIR> bin
2012-10-08 11:45 <DIR> src
2 个文件 681 字节
5 个目录 95,380,144,128 可用字节
Exited with error code 0