日期:2014-05-20 浏览次数:20867 次
[color=#FF0000]问题1:[/color]请看下面注释,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); } } }
public class OSExecuteDemo { public static void main(String[] args){ OSExecute.command("javap OSExecute"); } } public class OSExecuteException extends RuntimeException{ public OSExecuteException(String why){ super(why); } }