?? 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 + -