1 import com.ms.mtx.*; 2 import com.ms.asp.*; 3 import com.ms.com.*; 4 import java.io.*; 5 import java.net.URL ; 7 8 13 public class ProcessStarter4ASP 14 { 15 16 private IResponse iResponseObject; 17 19 20 26 27 30 public ProcessStarter4ASP() 31 { 32 IGetContextProperties iConProps = (IGetContextProperties)MTx.GetObjectContext(); 34 Variant vResponse = iConProps.GetProperty("Response"); 36 iResponseObject = (IResponse) vResponse.getDispatch(); 37 } 39 40 44 public void write(String s) 45 { 46 Variant vMsg = new Variant(s + "\n"); 47 iResponseObject.Write(vMsg); 48 } 49 50 54 public void startProcess(String cmd) 55 { 56 Runtime rt = Runtime.getRuntime(); 57 Process proc = null; 58 try 59 { 60 70 proc = rt.exec(cmd); 72 InputStream in = proc.getInputStream(); 73 BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 74 String line; 75 while ((line = reader.readLine()) != null) 76 { 77 write(line); 78 try 79 { 80 Thread.sleep(100); 81 } 82 catch (InterruptedException e) 83 { 84 write(e.toString()); 85 } 86 } 87 InputStream err = proc.getErrorStream(); 88 BufferedReader errreader = new BufferedReader(new InputStreamReader(err)); 89 while ((line = errreader.readLine()) != null) 90 { 91 write(line); 92 try 93 { 94 Thread.sleep(100); 95 } 96 catch (InterruptedException e) 97 { 98 write(e.toString()); 99 } 100 } 101 } 102 catch (Exception e) 103 { 104 write(e.toString()); 105 } 107 try 108 { 109 proc.waitFor(); 110 } 111 catch (InterruptedException e) 112 { 113 write(e.toString()); 114 } 115 if ( proc != null ) 116 { 117 proc.destroy(); 118 } 119 } 120 } | Popular Tags |