1 需求
实验对象分类(cmd命令、start命令):
- 可以在cmd窗口运行的命令
- PING.exe:命令需要执行一段时间
- dir.exe:命令瞬间运行完毕
- notepad.exe:无法在cmd窗口运行的命令
结论:
- process.waitFor()中process是指cmd.exe,而不是notepad.exe
2 接口
3.1 cmd /c notepad
import java.io.IOException;
public class RceDemo {
public static void main(String[] args) throws IOException, InterruptedException {
System.out.println(1);
Process process = Runtime.getRuntime().exec("cmd /c notepad");
process.waitFor();
System.out.println(2);
}
}