1 34 35 36 package com.micronova.util; 37 38 import java.io.*; 39 40 41 42 public class Shell 43 { 44 Pipe _inPipe; 45 Pipe _outPipe; 46 Pipe _errPipe; 47 Process _process; 48 49 public Shell(Process process, InputStream in, OutputStream out, OutputStream err) 50 { 51 super(); 52 53 _process = process; 54 55 _inPipe = new Pipe(in, process.getOutputStream()); 56 _outPipe = new Pipe(process.getInputStream(), out); 57 _errPipe = new Pipe(process.getErrorStream(), err); 58 } 59 60 public int exec() 61 { 62 try 63 { 64 Thread inThread = new Thread (_inPipe); 65 Thread outThread = new Thread (_outPipe); 66 Thread errThread = new Thread (_errPipe); 67 68 inThread.start(); 69 outThread.start(); 70 errThread.start(); 71 72 int rc = _process.waitFor(); 73 74 inThread.join(); 75 outThread.join(); 76 errThread.join(); 77 78 return rc; 79 } 80 catch (Exception e) 81 { 82 e.printStackTrace(); 83 } 84 85 return -1; 86 } 87 88 } 89 | Popular Tags |