调用Runtime.getRuntime().exec("cmd /c start")可以弹出一个dos窗口,并且该方法返回一个Process对象,该类提供了获得输入、输出流的方法getInputStream(),和getOutputStream()方法;但是我下面这样为什么不能将弹出窗口中的输入,输出到控制台呢?各位大侠帮帮忙啊~    InputStreamReader is = new InputStreamReader(proc.getInputStream());
    BufferedReader output = new BufferedReader(is);
    String outline;
    while ((outline = output.readLine()) != null) {
System.out.println(outline);
    }

解决方案 »

  1.   


    public class TestRuntime { public static void main(String[] args) throws IOException {
    String filename = "D:\\Program\\TestCode\\out.txt";
    String command = "cmd   /C   dir"; Runtime r = Runtime.getRuntime();
    Process p = r.exec(command); InputStreamReader is = new InputStreamReader(p.getInputStream());
    BufferedReader output = new BufferedReader(is);
    String outline;
    while ((outline = output.readLine()) != null) {
    System.out.println(outline);
    }
    }
      

  2.   

    那个command 中间要加一个start才能弹出dos窗口啊,而且这样也不能将dos里的输入读出来写到控制台