📄 runcommand.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 + -