osexecute.java
来自「看thinkinjava学习java时」· Java 代码 · 共 35 行
JAVA
35 行
package myutils;
import java.io.*;
public class OSExecute {
public static void command(String command){
boolean err = false;
try{
Process process = new ProcessBuilder(command.split("")).start();
BufferedReader results = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String s;
while((s = results.readLine())!= null)
System.out.println(s);
BufferedReader errors = new BufferedReader(
new InputStreamReader(process.getErrorStream()));
//report errors and return nonzero valus to calling process if there are problems
while((s = errors.readLine())!= null){
System.err.println(s);
err = true;
}
}catch(Exception e){
//compensste for windows 2000, which throw an exception for the default command line:
if(command.startsWith("CMD/C"))
command("CMD/C"+command);
else
throw new RuntimeException(e);
}
if(err)
//throw new OSExecuteException("Errors executing" + command);
System.out.println("Errors2 executing" + command);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?