JAVA与C#程序调用DOS命令
1.Java 代码 package CmdTest; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CmdTest { public static void main(String[] args) throws Throwable { // TODO Auto-generated method stub // 定义一个字符串用来输出DOS命令的结果 String strCmd; // 用来执行DOS命令 Process process = Runtime.getRuntime().exec( " cmd /c netstat -an " ); // 将命令的结果以流的方式读入 BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream())); // 将结果循环打印输出 while ((strCmd = bufferedReader.readLine()) != null ) { System.out.println(strCmd); } // 子线程结束后要杀掉 process