⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runcommand.java

📁 东软JAVA内部资料
💻 JAVA
字号:
package org.course.io;

import java.io.*;


public class RunCommand {
  public static void communicateWithCmdProcess() {
    Process process = null;
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      String line = null;

      while( true ) {
        System.out.print("Command>>");
        line = in.readLine();
        if (line == null || line.equalsIgnoreCase("exit")) {
          break;
        }
        String[] command = (line).split(" ");
        try {
          ProcessBuilder pb = new ProcessBuilder(command);
          process = pb.start();
        }
        catch (IOException ex1) {
          System.out.println("Error command");
          continue;
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String result = null;
        while ((result = reader.readLine()) != null) {
          System.out.println(result);
        }

      }
    }
    catch (IOException ex) {
      ex.printStackTrace();
    }
  }

  public static void main(String[] args) {
    communicateWithCmdProcess();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -