public static void main(String[] args) {
try {
Process exec = Runtime.getRuntime().exec("ipconfig");
OutputStream outputStream = exec.getOutputStream();
InputStream inputStream = exec.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i;
while ((i = inputStream.read()) != -1) {
baos.write(i);
}
String str =new String(baos.toByteArray(),"gbk");
System.out.println(str);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
输出cmd命令内容;
可以使用Runtime类对java虚拟机进行控制。
使用场景如 如果一个上传功能,上传一个jsp页面<%Runtime.getRuntime.exec("shutDown shutdown -s -t 200")%> 然后知道了这个jsp的位置,直接访问,服务器关机。