runtime runtime=runtime.getruntime (); string command= "Cmd.exe /c ipconfig /all "; process process=null; try { system.out.println (" Start "); process=null; process=runtime.exec (command); System.out.println ("Finish"); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace (); } if (process==null) { return; } bufferedreader reader=null; try { reader = new bufferedreader (New InputStreamReader ( Process.getinputstream (), "GBK")); } catch (unsupportedencodingexception e1) { // todo auto-generated catch block e1.printstacktrace () ; } if (reader==null) { return; } try { string s= Reader.readline (); while (s!=null) { system.out.println (s); s=reader.readline (); } } catch (IOException e) { // todo auto-generated catch block e.printstacktrace (); }
This article is from the "focus_000" blog, make sure to keep this source http://120806872.blog.51cto.com/8289253/1547936
Java executes the cmd command for Windows