" tree"命令我的程序输出不完整。谁能帮我解决一下呢?
public static void main(String[] args) {
for (;;) {
try {
String command = JOptionPane.showInputDialog("> ");
Process p = Runtime.getRuntime().exec("cmd /C " + command);
Scanner sc = new Scanner(p.getInputStream());
while (sc.hasNext()) {
System.out.println(sc.nextLine());
}
if ("exit".equals(command)) {
System.exit(0);
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
答案 0 :(得分:0)
我在你的代码中看到的唯一可能明显的事情是,你的命令输入将只占用一个(并且只有一个命令) - 而且你可能想要刷新两个
while (sc.hasNext()) {
System.out.println(sc.nextLine());
System.out.flush(); // <-- To get all your output, before exit?
}