publicclassOSExcute{publicstaticvoidcommand(String command){boolean err =false;try{
String[] commands = command.split(" ");
System.out.println(Arrays.toString(commands));
Process process =newProcessBuilder((commands)).start();
BufferedReader results =newBufferedReader(newInputStreamReader(process.getInputStream()));
String s;while((s = results.readLine())!= null)
System.out.println(s);
BufferedReader errors =newBufferedReader(newInputStreamReader(process.getErrorStream()));//report errors and return nonzero value to calling process if there are problemswhile((s = errors.readLine())!= null){
System.err.println(s);
err =true;}}catch(Exception e){//Compensate for Windows 2000,which throws an exception for the default command line:if(command.startsWith("CMD /C"))command("CMD /C"+ command);elsethrownewRuntimeException(e);};if(err)thrownewOSExcuteException("Errors excuting "+ command);}}