importjava.io.BufferedInputStream;importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;publicclassTestNetstat{/***@paramargs*/publicstat...
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TestNetstat {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stubss
String getPid = "netstat -ano | findstr \"5576\"";
Runtime run = Runtime.getRuntime();
try {
Process vmState = run.exec(new String[]{"cmd.exe","/c","netstat -ano | findstr \"5576\""});
BufferedInputStream bisVmState = new BufferedInputStream(vmState.getInputStream());
BufferedReader brVmState = new BufferedReader(new InputStreamReader(bisVmState));
String tmpVmState ="";
tmpVmState =brVmState.readLine();
while ((tmpVmState = brVmState.readLine()) != null){
System.out.println(tmpVmState);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
展开