package com.why;
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter;
public class Cmd {
public static void main(String[] args) { try { //Process p = Runtime.getRuntime().exec(new String[] { "cmd", "/c", "dir" }); Process p = Runtime.getRuntime().exec("cmd");
PrintWriter out = new PrintWriter(new OutputStreamWriter(p.getOutputStream()), true); out.println("cd c:\\"); out.println("dir"); out.println("exit");
///p.waitFor(10, TimeUnit.SECONDS); p.waitFor();
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream(),"GBK"));
String line = null; while ((line = input.readLine()) != null) { System.out.println(line); }
input.close(); out.close();
} catch (Exception e) { e.printStackTrace(); }
}
}
|