java调用外部控制台出现的小问题?至今没想明白

来源:互联网 发布:夏普电视机推荐 知乎 编辑:程序博客网 时间:2024/05/16 19:00

public static void main(String[] args0) {
  try{
            Process process = Runtime.getRuntime().exec ("ipconfig");  
            InputStreamReader ir=new InputStreamReader(process.getInputStream());  
            BufferedReader input = new BufferedReader (ir);  
            String line;  
            StringBuffer str = new StringBuffer();
            int exitVal = process.waitFor();
           
             while ((line = input.readLine()) != null) {
                 String temp =line;
                 str.append(temp+"/r/n");
              System.out.println(line);
              //System.out.println(input.readLine());
              
                    }
    
   
           
           
            System.out.println(exitVal);
            System.out.println(str.toString());
        }catch(Exception e){
            System.err.println ("IOException " + e.getMessage());  
        }

 }


 

为什么直接输出input.readline(),控制台输出的都是空呢?是传说中的缓冲区问题?赋值一下就可以了呢?

原创粉丝点击