请看下面一段代码
Runtime run = Runtime.getRuntime();
Process p = run.exec("C:\WINDOWS\system32\cmd.exe");
BufferedReader br = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String str = null;
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
p.getOutputStream()));
Scanner sc = new Scanner(System.in);
while (true) {
while ((str = br.readLine()) != null) {
System.out.println("--" + str);
}
String cmd = sc.nextLine();
System.out.println(cmd);
if (cmd.equalsIgnoreCase("q") || cmd.equalsIgnoreCase("exit")) {
break;
}
bw.write(cmd);
bw.flush();
}
p.destroy();
bw.close();
br.close();
愿意是想在控制台模拟dos界面,程序执行后,输入命令
System.out.println(cmd);却没有输出,一直阻塞,请问各位大虾能提点一下么?