请问我这段程序哪儿出错了?为什么不显示结果,字符串s和“error”都不打印出来:import java.io.IOException;
import java.io.*;public class compile {
public static void main(String[] args){
try {
            InputStream p = Runtime.getRuntime().exec("ipconfig /all").getInputStream();
        
            String s = (new BufferedReader(new InputStreamReader(p))).readLine();
        
        if(s!=null)System.out.println(s);
        else System.out.println("error");
     } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

解决方案 »

  1.   

    你的命令写错了好像应该是
    InputStream p = Runtime.getRuntime().exec("cmd /c ipconfig /all").getInputStream(); 
             
      

  2.   

    InputStream p = Runtime.getRuntime().exec("cmd /c ipconfig -all").getInputStream();  
      

  3.   

    system command是没错 只是你获取的方式
    第一行本来就是空行
      

  4.   

    import java.io.IOException; 
    import java.io.*; public class compile { 
    public static void main(String[] args){ 
    try { 
                InputStream p = Runtime.getRuntime().exec("cmd /c ipconfig -all").getInputStream(); 
                 BufferedReader b = new BufferedReader(new InputStreamReader(p));
     String s = "";
      while( (s = b.readLine()) != null)
          {
                  System.out.println(s); 
          }
         } catch (IOException e) { 
    e.printStackTrace(); 


    }