public static void main(String[] args) {
InputStream ins = null;
//&&可以执行多条命令
//路径参数注意 要么\\ or /
// String[] cmd = new String[] { "cmd.exe","/C","cd /d E:/1&&java com.stx.frame.TestCmd"};
String cmd="cmd.exe /c dir";
try {
Process process = Runtime.getRuntime().exec(cmd);
ins = process.getInputStream(); //cmd 的信息
BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line); //输出
}
int exitValue = process.waitFor();
System.out.println("返回值:" + exitValue);
process.getOutputStream().close(); //不要忘记了一定要关
} catch (Exception e) {
e.printStackTrace();
}
}