用Java调用计算机程序
import java.io.IOException;
public class WebShell {
public static void main(String[] args) throws IOException {
Runtime.getRuntime().exec("calc");
}
}
调用cmd命令
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
public class Ping {
public static void main(String[] args) throws IOException {
Process pro = Runtime.getRuntime().exec(new String[]{"cmd","/c","ping www.baidu.com"});
InputStream in = pro.getInputStream();
Scanner sc = new Scanner(in);
while (sc.hasNextLine()){
System.out.println(sc.nextLine());
}
}
}