问题1:请看下面注释,CMD/C 是啥东西?
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()));
while((s = errors.readLine()) != null){
System.err.println(s);
err = true;
}
}catch(Exception e){
if(!command.startsWith("CMD/C")){ //这里的CMD/C是什么意思,为什么要以这个结尾?
command("CMD/C " + command);
}else{
throw new RuntimeException();
}
}
if(err){
throw new OSExecuteException("Errors executing " + command);
}
}
}问题2:下面两段代码是上面代码的补充,可是 eclipse 里不能正常运行,我只能通过 命令提示符 来验证,不知道为什么 eclipse 不能运行,请教下
public class OSExecuteDemo { public static void main(String[] args){
OSExecute.command("javap OSExecute");
}
}public class OSExecuteException extends RuntimeException{ public OSExecuteException(String why){
super(why);
}
}
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()));
while((s = errors.readLine()) != null){
System.err.println(s);
err = true;
}
}catch(Exception e){
if(!command.startsWith("CMD/C")){ //这里的CMD/C是什么意思,为什么要以这个结尾?
command("CMD/C " + command);
}else{
throw new RuntimeException();
}
}
if(err){
throw new OSExecuteException("Errors executing " + command);
}
}
}问题2:下面两段代码是上面代码的补充,可是 eclipse 里不能正常运行,我只能通过 命令提示符 来验证,不知道为什么 eclipse 不能运行,请教下
public class OSExecuteDemo { public static void main(String[] args){
OSExecute.command("javap OSExecute");
}
}public class OSExecuteException extends RuntimeException{ public OSExecuteException(String why){
super(why);
}
}
2、那就是eclipse的原因了
不是结尾是开始