1 23 24 package com.sun.enterprise.deployment.backend; 25 26 import java.util.logging.Level ; 27 import java.io.InputStream ; 28 import java.io.IOException ; 29 30 31 35 public class ProcessWatcher { 36 37 Process toWatch = null; 38 39 40 public ProcessWatcher(Process p) { 41 toWatch = p; 42 } 43 44 public int watch() { 45 InputStream input = toWatch.getInputStream(); 46 InputStream error = toWatch.getErrorStream(); 47 boolean notDone = true; 48 do { 49 try { 50 while (input.available()>0) { 51 dump(input); 52 } 53 while (error.available()>0) { 54 dump(error); 55 } 56 } catch(IOException e) { 57 58 } 59 try { 60 toWatch.exitValue(); 61 notDone = false; 62 } catch(IllegalThreadStateException e) { 63 } 64 } while (notDone); 65 return toWatch.exitValue(); 66 } 67 68 public void dump(InputStream is) throws IOException { 69 if (is.available()>0) { 70 byte[] bytes = new byte[is.available()]; 71 is.read(bytes, 0, bytes.length); 72 System.out.println(new String (bytes)); 73 } 74 } 75 } 76 | Popular Tags |