1 29 30 package com.caucho.server.boot; 31 32 import com.caucho.vfs.ReadStream; 33 import com.caucho.vfs.Vfs; 34 35 import java.io.IOException; 36 import java.io.InputStream; 37 import java.util.logging.Level; 38 import java.util.logging.Logger; 39 40 43 public class ProcessManager { 44 private static final Logger log = 45 Logger.getLogger(ProcessManager.class.getName()); 46 47 private volatile Process _process; 48 49 void start() 50 throws IOException 51 { 52 Runtime runtime = Runtime.getRuntime(); 53 54 _process = runtime.exec(new String[] {"java", "com.caucho.server.resin.Resin" }, 55 new String[] {"CLASSPATH=lib/resin.jar"}); 56 57 try { 58 new ReadThread(_process.getInputStream()).start(); 59 new ReadThread(_process.getErrorStream()).start(); 60 61 int status = waitForStatus(); 62 63 System.out.println("STATUS:" + status); 64 } finally { 65 _process = null; 66 } 67 } 68 69 private int waitForStatus() 70 { 71 while (true) { 72 try { 73 return _process.waitFor(); 74 } catch (InterruptedException e) { 75 log.log(Level.WARNING, e.toString(), e); 76 } 77 } 78 } 79 80 class ReadThread extends Thread { 81 private ReadStream _is; 82 private char []cBuf = new char[1024]; 83 84 ReadThread(InputStream is) 85 { 86 _is = Vfs.openRead(is); 87 } 88 89 public void run() 90 { 91 while (_process != null) { 92 try { 93 int len = _is.read(cBuf, 0, cBuf.length); 94 95 if (len < 0) 96 return; 97 98 System.out.print(new String(cBuf, 0, len)); 99 } catch (IOException e) { 100 } 101 } 102 } 103 } 104 } 105 | Popular Tags |